Archive for April, 2007

62Part IPHP: The (Multiple domain web hosting) BasicsPHP syntax is relevant only

Monday, April 30th, 2007

62Part IPHP: The BasicsPHP syntax is relevant only within PHP, so we assume for the rest of this chapter that PHPmode is in force that is, most code fragments will be assumed to be embedded in an HTMLpage and surrounded with the appropriate tags. PHP s Syntax Is C-LikeThe third most important thing to know about PHP syntax is that, broadly speaking, it is likethe C programming language. If you happen to be one of the lucky people who already knowC, this is very helpful; if you are uncertain about how a statement should be written, try itfirst the way you would do it in C, and if that doesn t work, look it up in the manual. The restof this section is for the other people, the ones who don t already know C. (C programmersmight want to skim the headers of this section and also see Appendix A, which is specificallyfor C programmers.) PHP is whitespace insensitiveWhitespaceis the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns (end-of-line characters). PHP s whitespace insensitivity does notmean that spaces and such never matter. (In fact, they are crucial for separating the wordsinthe PHP language.) Instead, it means that it almost never matters how manywhitespace char- acters you have in a row one whitespace character is the same as many such characters. For example, each of the following PHP statements that assigns the sum of 2+2to the vari- able $fouris equivalent: $four = 2 + 2; // single spaces$four =2+2 ; // spaces and tabs$four = 2+ 2; // multiple linesThe fact that end-of-line characters count as whitespace is handy, because it means younever have to strain to make sure that a statement fits on a single line. PHP is sometimes case sensitiveHaving read that PHP isn t picky, you may be surprised to learn that it is sometimes case sensitive (that is, it cares about the distinction between lowercase and capital letters). In particular, all variables are case sensitive. If you embed the following code in an HTML page: ); print( Variable CaPiTaL is $CaPiTaL
); ?> The output you will see is: Variable capital is 67Variable CaPiTaL is07
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Syntax andVariablesIn this chapter, we (Web hosting ratings) cover the basic

Monday, April 30th, 2007

Syntax andVariablesIn this chapter, we cover the basic syntax of PHP the rules that allwell-formed PHP code must follow. We explain how to use variablesto store and retrieve information as your PHP code executes and thetype system that governs what kinds of values can be stored in thefirst place. Finally, we look at the simplest ways to display text thatwill show up in your user s browser window. PHP Is ForgivingThe first and most important thing to say about the PHP language isthat it tries to be as forgiving as possible. Programming languagesvary quite a bit in terms of how stringently syntax is enforced. Pickiness can be a goodthing because it helps make sure that thecode you re writing is really what you mean. If you are writing a pro- gram to control a nuclear reactor and you forget to assign a variable, it is far better to have the program be rejected than to create behav- ior different from what you intended. PHP s design philosophy, how- ever, is at the other end of the spectrum. Because PHP started life asa handy utility for making quick-and-dirty Web pages, it emphasizesconvenience for the programmer over correctness; rather than havea programmer do the extra work of redundantly specifying what ismeant by a piece of code, PHP requires the minimum and then triesits best to figure out what was meant. Among other things, thismeans that certain syntactical features that show up in other lan- guages, such as variable declarations and function prototypes, aresimply not necessary. With that said, though, PHP can t read your mind; it has a minimumset of syntactical rules that your code must follow. Whenever you seethe words parseerrorin your browser window instead of the coolWeb page you thought you had just written, it means that you ve bro- ken these rules to the point that PHP has given up on your page. HTML Is Not PHPThe second most important thing to understand about PHP syntax isthat it applies only within PHP. Because PHP is embedded in HTMLdocuments, every part of such a document is interpreted as eitherPHP or HTML, depending on whether that section of the document isenclosed in PHP tags. 55CHAPTER …In This ChapterUnderstanding the basicrules of PHPStoring information variables, and data typesOutput to HTML …
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

59Chapter 4Adding PHP to (Web site development) HTMLSummaryPHP is easy to

Monday, April 30th, 2007

59Chapter 4Adding PHP to HTMLSummaryPHP is easy to embed in HTML. You can use whatever HTML-production method you realready comfortable with and simply add the PHP sections later. PHP additions can rangefrom simply echoing a single-digit integer to writing long chunks of code. Every PHP block, short or long, is set off by PHP tags. There are several styles of PHP tags, but everyone should be encouraged to use the canonical style. You can also include PHP infiles by using the includefunctions but remember that the contents of the included fileswill not be recognized as PHP unless surrounded by PHP tags. …
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

58Part IPHP: The BasicsThey are called from a (Free web hosts)

Monday, April 30th, 2007

58Part IPHP: The BasicsThey are called from a PHP page this way:

This is some body text for this particular page.

Obviously, this single move greatly enhances the maintainability and scalability of an entiresite. Now, if you want a different look and feel or if you need to update the copyright notice, you can alter one file instead of identical lines in dozens of HTML pages. When including files, remember to set the include_pathdirective correctly in yourphp.inifile. Remember that you can include files from above or entirely outside your Webtree by proper use of this directive. See Chapter 30 for more information. As you can see from the preceding example, PHP s includefunctions simply pass along thecontents of the included file as text. Many people think that because an includefunctionoccurs inside PHP mode, the included file will also be in PHP mode. This is not true! Actually, the server escapes back into HTML mode at the beginning of each included file and silentlyreturns to PHP mode at the end, just in time to catch the semicolon. As always, you need to say when you intend something to be PHP by using PHP opening andclosing tags. Any part of an included file that needs to be executed as PHP should beenclosed in valid PHP tags. If the entire file is PHP (very common in files of functions), theentire file must be enclosed within PHP tags. Take the following file, database.inc: $db = mysql_connect( localhost , db_user , db_password ); mysql_select_db( my_database ); We can t emphasize this enough: If you re having problems including PHP files, particularly ifyou re seeing output you don t expect or not seeing output you do expect, be ABSOLUTELYPOSITIVEthat you ve put PHP tags at the beginning and end of the included file. If you were to foolishly include this file from a PHP script, your database variables would bevisible to the world in plain text because you neglected to use PHP tags, the parser assumesthis block of code is HTML. A correct version of the database.incfile would look like this: For all PHP files included from other files, you must ensure that there are no empty new linesat the end of the file. Remember, anything outside a PHP block is considered HTML, even ablank line. Blank lines, or even blank spaces outside a closing PHP tag, will be interpreted asoutput. If you include the file in a situation where you cannot have output say before usingHTTP headers your script will fail with a big error message about the output stream havingalready been started in your included file. See Chapter 11 for an example. CautionCautionTip06
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

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

Sunday, April 29th, 2007

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

56Part IPHP: The BasicsFigure 4-1:Your (Freelance web design) first PHP scriptRefer

Sunday, April 29th, 2007

56Part IPHP: The BasicsFigure 4-1:Your first PHP scriptRefer to Chapter 3 for installation instructions, and forward to Chapter 30 for configurationoptions. Chapter 11 diagnoses some common early problems and gives debugging hints. Jumping in and out of PHP modeAt any given moment in a PHP script, you are either in PHP mode or you re out of it in HTML. There s no middle ground. Anything within the PHP tags is PHP; everything outside is plainHTML, as far as the server is concerned. You can escape into PHP mode with giddy abandon, as often and as briefly or lengthily asnecessary. For example:

First name:

Last name:

Rank: >


Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

55Chapter 4Adding PHP to HTMLIf you ve made the (Web hosts)

Sunday, April 29th, 2007

55Chapter 4Adding PHP to HTMLIf you ve made the virtuous decision to eschew the short-open tag, remember to disable it inyour php.inifile. You want to see an error message when you inadvertently forget to com- plete your tag correctly. ASP-style tagsASP-style tags mimic the tags used by Microsoft Active Server Pages to delineate code blocks. ASP-style tags look like this: <% %> People who use FrontPage as a development tool often choose this style. To use ASP-styletags, you will need to set the configuration option in your php.inifile. Obviously, if you useASP-style tags and the .aspsuffix (which you may wish to do if you re converting from anASP site or spoofing ASP for some reason), you will need to disable ASP on your IIS server. Otherwise, two different scripting engines will be trying to parse the same blocks of codewith unpredictable results. HTML script tagsHTML script tags look like this: Although this is effective and also gets around the FrontPage problems, it can be cumber- some in certain situations, such as quick pop-in variable replacement. In particular, be carefulif you use lots of JavaScript on your site since the close-script tags are fatally ambiguous. TheHTML script tag is best used for fairly sizable blocks of PHP code. Hello WorldNow we re ready to write our first PHP program. Open a new file in your preferred editor. Type: My first PHP program
n ); phpinfo(); ?> In most browsers, nothing but the PHP section is strictly necessary. However, it s a good ideato get in the habit of always using a well-formed HTML structure in which to embed your PHP. If you don t see something pretty close to the output shown in Figure 4-1, you have a problem most likely some kind of installation or configuration glitch. Review Chapter 3, and make doublysure your installation succeeded. Tip06
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

54Part IPHP: The BasicsEverything within (Email web hosting) these tags is

Saturday, April 28th, 2007

54Part IPHP: The BasicsEverything within these tags is understood by the PHP parser to be PHP code. Everythingoutside of these tags does not concern the server and will simply be passed along and left forthe client to sort out whether it s HTML or JavaScript or something else. There are four styles of PHP tags and different rationales for using them. Part of the decision, however, is simply individual preference: what the individual programmer is comfortable withor what a team has decided upon for reasons of their own. Canonical PHP tagsThe most universally effective PHP tag style is: If you use this style, you can be positive that your tags will always be correctly interpreted. Unless you have a very, very strong reason to prefer one of the other styles, use this one. Some or all of the other styles of PHP tag may be phased out in the future only this one iscertain to be safe. Short-open (SGML-style) tagsShort or short-open tags look like this: Short tags are, as one might expect, the shortest option. Those who escape into and out ofHTML frequently in each script will be attracted by the prospect of fewer keystrokes; how- ever, the price of shorter tags is pretty high. You must do one of two things to enable PHPtorecognize the tags: .Choose the –enable-short-tagsconfiguration option when you re building PHP. .Set the short_open_tagsetting in your php.inifile to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags. There used to be a third way to enable short-open tags: the short_open()function. Thisceased to be supported as of PHP4. There are several reasons to resist the temptation of the short-open tag. The most compellingreason now is that this syntax is not compatible with XML and since XHTML is a type ofXML, this implies that none of your code will be able to validate as XHTML. PHP code writtenwith short-open tags is less portable because you can t be sure another machine will haveenabled them. Short-open tags are also harder to pick out visually on the page, and many syn- tax-highlighting schemes don t support them. Beginners should be encouraged to start offwith the canonical style tag if at all possible. The short-open tag was one of many hacky ease-of-use ideas that ended up biting the PHPcommunity years later. The PHP development team must now struggle to balance desires fora more standard and consistent syntax with a large installed userbase, which has written ahuge pile of code in the old style. As XML becomes more and more central to Web develop- ment, and as we move toward XHTML as the standard for Web page development, the short- open tag faces a shaky future. Do yourself a favor and start moving toward the canonical PHPtags now. Caution06
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services

Adding PHP to HTMLAfter all those preliminary exertions, (Web domain)

Saturday, April 28th, 2007

Adding PHP to HTMLAfter all those preliminary exertions, we finally get to the point ofwriting our first PHP scripts. Here you ll learn about PHP mode, PHP tags, and how to include other files in your PHP scripts. You llalso write your very first PHP program. Your HTML Is Already PHP-Compliant! PHP is already perfectly at home with HTML in fact, it is generallyembedded within HTML. As you ll see in later chapters, PHP ridespiggyback on some of the cleverer parts of the HTML standard, suchas forms and cookies, to do all kinds of useful things. Anything compatible with HTML on the client side is also compatiblewith PHP. PHP could not care less about chunks of JavaScript, calls tomusic and animation, applets, or anything else on the client side. PHPwill simply ignore those parts, and the Web server will happily passthem on to the client. It should thus be clear that you can use any method of developingWeb pages and simply add PHP to that method. If you re comfortablehaving teams work on each page using huge multimedia graphicssuites, you can keep on doing that. The general point is that youdon t need to change tools or workflow order just do what you vebeen doing and add the server-side functionality at the end. Escaping from HTMLBy now you re probably wondering: How does the PHP parser recog- nize PHP code inside your HTML document? The answer is that youtell the program when to spring into action by using special PHP tagsat the beginning and end of each PHP section. This process is calledescaping from HTMLor escaping into PHP. Not to confuse you, but escapein this sense should not be con- fused with another common use of the term escapein PHP: putting a backslash in front of certain special characters (such astab and newline) within double-quoted strings. Escaping strings isexplained in Chapter 8. Caution44CHAPTER …In This ChapterEscaping into PHPmodeChoosing PHP tag stylesWriting a Hello Worldprogram in PHPIncluding files …
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

Free web hosting services - 51Chapter 3Getting Started with PHPIf you decide to

Saturday, April 28th, 2007

51Chapter 3Getting Started with PHPIf you decide to self-host or maintain a development environment, detailed installationinstructions are provided in previous sections of this chapter for the most common plat- forms. PHP5 has SAPI support for many other Web servers, but installation directions for allof them would have made this chapter unreasonably lengthy. Finally, before you can start developing, you will want to give some thought to which develop- ment tools are best adapted to PHP. Although the long-awaited PHP-specific IDE is now avail- able from Zend, most PHP developers still simply use their favorite text editors. It is possibleto add PHP to the product of a WYSIWYG editor, but it can be messy. …
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services