If you use the traditional output method--by string output--there must be a large number of escape characters to escape the special characters in the string, such as quotes, so that there is no syntax error. If it's one or two, you can tolerate it, but if you have a full HTML text or a 200-line JS, I think everyone will crash. That's why PHP introduces a delimiter--at least for a large part of it.
The function of the 1.PHP delimiter is to follow the original, including the line-wrapping format or something, and output it inside;
2. No special characters in the PHP delimiter need to be escaped;
The PHP variable in the 3.PHP delimiter is normally replaced with its value.
The delimiter format in PHP is this:
Copy Code code as follows:
It looks simple, but there are a lot of places to pay attention to.
The first character EOF after <<< is defined by itself, anything is possible (such as AAA can), but the character at the end must be the same as his, they appear in pairs, like {}--this is the most basic.
The second problem that needs to be noted in the use of PHP delimiters is the most frequent problem:
The end of the line (for example, EOF;), be sure to start a different line, and a row except EOF, the end of this delimiter can not have any other characters, including spaces. If you have a blank or tab at the end of the line, you will receive an error message like this:
Parse error:parse error, unexpected $end in ..., prompts you grammatical error;
The third thing to note is that if there is a PHP variable in the middle of the delimiter, you just need to write as if it were output in other strings, such as
Copy Code code as follows:
Variable $name The reason to use {} is to tell the PHP parser this is a PHP variable, in fact, it is not possible, but there may be ambiguity, such as your variable is not just a letter or a special symbol of what will happen? There's no way to do this.
Copy Code code as follows:
<<<eof
hello<?php Echo $name?>
Eof;
In this case, you will also receive a syntax error message. The first is a field test of the PHP delimiter to the correct wording. It contains code for HTML and javascript:
Copy Code code as follows:
<?php
$name = ' Kitty ';
Echo <<<eof
<table height= ">
<tr><td>
{$name}<br/>
<scr Ipt>
var p= ' Hello World ';
Document.writeln (P);
</script>
</td></tr>
</table>
Eof;
?>