Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

your PHP script. Put a linefeed where a linefeed would appear if you were coding the
page without PHP. You will spend less time picking through your output.


Related to backslash codes are embedded variables. You may write a variable inside a
string surrounded by double quotes, and its value will appear in its place. This even
works with arrays and objects. Listing 2.3 is an example of this technique. Notice that the
RowColor variable appears within a print statement between double quotes.


Table 2.3. Backslash Codes
Code Description

\" (^) Double Quotes
\ (^) Backslash Character
\n (^) New Line
\r (^) Carriage Return
\t (^) Horizontal Tab
\x00 - \xFF (^) Hex Characters
Borrowing from Perl, PHP also allows what are sometimes called "here docs". A special
operator allows you to specify your own string of characters that mean the end of a string.
This is helpful when you have large blocks of text that span multiple lines and contain
quotes. Backslash codes and variables are recognized inside the text block, just as they
are with string surrounded by double quotes. To mark an area of text, begin by using the
<<< operator. Follow it by the identifier you'll use to end the string. When that identifier
is found alone on a line, PHP will consider it equivalent to a closing quote character. The
identifier you choose must follow the same rules governing the naming of any other
identifier, as described above. It's customary to use HERE or EOD (end of data). See Listing
2.4 for an example.
Listing 2.4 HERE docs

Free download pdf