Prev | Current Page 171 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

However, if the backslash were to appear anywhere else within the
string, there would be no need to escape it.
Heredoc
Heredoc syntax offers a convenient means for outputting large amounts of text. Rather
than delimiting strings with double or single quotes, two identical identifiers are
employed. An example follows:
$website = "http://www.romatermini.it";
echo <<

Rome's central train station, known as Roma Termini,
was built in 1867. Because it had fallen into severe disrepair in the late 20th
century, the government knew that considerable resources were required to
rehabilitate the station prior to the 50-year Giubileo.


EXCERPT;
?>
98 CHAPTER 3 ?–  PHP B ASICS
Several points are worth noting regarding this example:
??? The opening and closing identifiers, in the case of this example, EXCERPT, must be
identical. You can choose any identifier you please, but they must exactly match.
The only constraint is that the identifier must consist of solely alphanumeric characters
and underscores and must not begin with a digit or an underscore.
??? The opening identifier must be preceded with three left-angle brackets, <<<.
??? Heredoc syntax follows the same parsing rules as strings enclosed in double
quotes. That is, both variables and escape sequences are parsed. The only
difference is that double quotes do not need to be escaped.


Pages:
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183