Adult web hosting - 57Chapter 4Adding PHP to HTMLNotice that things that

57Chapter 4Adding PHP to HTMLNotice that things that happened in the first PHP mode instance in this case, a variablebeing assigned are still valid in the second. In Chapter 5, you ll learn more about what happens to variables when you skip in and out of PHP mode. In Chapter 33, you ll also learnabout different styles of using PHP mode. Including filesAnother way you can add PHP to your HTML is by putting it in a separate file and calling it byusing PHP s includefunctions. There are four includefunctions: .include( /filepath/filename ) .require( /filepath/filename ) .include_once( /filepath/filename ) .require_once( /filepath/filename ) In previous versions of PHP, there were significant differences in functionality and speedbetween the includefunctions and the requirefunctions. This is no longer true; the two sets of functions differ only in the kind of error they throw on failure. Include()andinclude_once()will merely generate a warning on failure, while require()andrequire_once()will cause a fatal error and termination of the script. As suggested by the names of the functions, include_once()and require_once()differfrom simple include()and require()in that they will allow a file to be included only onceper PHP script. This is extremely helpful when you are including files that contain PHP func- tions, because redeclaring functions results in an automatic fatal error. In larger PHP systems, it s quite common to include files which include other files which include other files it canbe difficult to remember whether you ve included a particular function before, but withinclude_once()or require_once()you don t have to. How do you decide on a preferred includefunction? In essence, you must decide whetheryou want to force yourself to write good code on pain of fatal error or whether you want it torun regardless of certain common errors on your part. The strictest alternative is require(), which will bring everything grinding to a halt if your code isn t perfect; the least strict isinclude_once(), which will good-naturedly hide the consequences of some of your bad coding habits. The most common use of PHP s includecapability is to add common headers and footers toall the Web pages on a site. For example, a simple header file (cleverly named header.inc) might look like this: A site title Similarly, a footer file called footer.incmight consist of:

Copyright 1995 - 2002


Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

Leave a Reply