Suppose you want to include A LOT of text (like several lines of code) as a String variable, and you don't want to escape all the possible quotation problems. Try this trick (called the Heredoc Syntax):
Now, if you try to echo the variable, you get:
Heredoc text behaves just like a double-quoted string, without the double-quotes. This means that you do not need to escape quotes in your here docs, but you can still use escape codes as elsewhere.
The end identifier (END_CONTENT; in the above example) must be the only thing on the line (it must be preceeded and followed by a '\r' and it must begin at the first character of the line.
Scripts using single quotes run slightly faster because the PHP parser can include the string directly. Double quoted strings are slower because they need to be parsed.
|Anatomy of a Class < < PREVIOUS||Table of Contents||NEXT > > Construct Tricks|
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2021, by Bill Sanders, all rights reserved.
This domain had 4,152 different visits in the last 30 days.
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 4:26 pm, MST
This file took 0.00997 seconds to process.