78Part IPHP: The BasicsWe could have used single (Web site builder)

78Part IPHP: The BasicsWe could have used single backslashes to produce the first two backslashes in the output, but the escaping is necessary at the end of the string so that the closing quote will notbeescaped. These two escape sequences (\and ) are the onlyexceptions to the literal-mindedness ofsingly quoted strings. Doubly quoted stringsStrings that are delimited by double quotes (as in this ) are preprocessed in both the following two ways by PHP: .Certain character sequences beginning with backslash () are replaced with specialcharacters. .Variable names (starting with $) are replaced with string representations of their values. The escape-sequence replacements are: .nis replaced by the newline character .ris replaced by the carriage-return character .tis replaced by the tab character .$is replaced by the dollar sign itself ($) . is replaced by a single double-quote ( ) .\is replaced by a single backslash () The first three of these replacements make it easy to visibly include certain whitespace characters in your strings. The $sequence lets you include the $symbol when you want it, without it being interpreted as the start of a variable. The sequence is there so that youcan include a double-quote symbol without terminating your doubly quoted string. Finally, because the character starts all these sequences, you need a way to include that characterliterally, without it starting an escape sequence to do this, you preface it with itself. Just as with singly quoted strings, quotes of the opposite type can be freely included withoutan escape character: $has_apostrophe = There s no problem here ; Single versus double quotation marksPHP does some preprocessing of doubly quoted strings (strings with quotes like this ) before constructing the string value itself. For one thing, variables are replaced by their val- ues (as in the preceding example). To see that this replacement is really about the quotedstring rather than the printconstruct, consider the following code: $animal = antelope ; // first assignment$saved_string = The animal is $animal
; $animal = zebra ; // reassignmentprint( The animal is $animal
); //first display lineprint($saved_string); //second display lineWhat output would you expect here? As it turns out, your browser would display: The animal is zebraThe animal is antelopeNote07
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply