Preface
Because PHP is a web programming language, it is inevitable that you will use echo to output large segments of html and javascript scripts during the programming process. If you use the traditional output method - output according to strings, you must have a large number of escape characters to escape special characters such as quotes in the string to avoid syntax errors. If it is one or two places, it can be tolerated, but if it is a complete html text or a 200-line js, I think anyone will crash. This is why PHP introduces a delimiter—at least for the most part.
The format of delimiter in PHP is as follows:
<<<Eof
……
Eof;
It looks simple, but there are many things to pay attention to.
Things to note when using the delimiter <<<
The delimiter identifier must be consistent before and after
Delimiter identifiers can be defined arbitrarily, such as echo html div, try to choose meaningful identifiers, and follow certain naming specifications.
The beginning mark cannot be followed by any characters, nor can spaces be used. After a line break, the text to be output.
The end logo (after followed by a semicolon;) must not have any characters before and after, that is, the end logo must be written at the top and occupy a single line. There must be no characters except the semicolon immediately followed by (the spaces are not allowed)
Finally, it should be noted that the line where the end logo is located cannot be the last line of the script, and there must be blank lines or other code lines below it, otherwise an error will be reported.
Examples are as follows:
<?php //Format one$a=<<<HTML <table> <tr>123<td></td><td></td><td></td></tr> </table> HTML; echo $a; //Format 2echo <<<EOT <table width=80% border="2" cellpadding="3" cellspacing="0" bordercolor="#808080"> <tr bgcolor="#84A9E1"> <td align="center">ClassID</td> <td align="center">stuno</td> <td align="center">Student name</td> <td align="center">Parent name</td> <td align="center">Parents' mobile number</td> </tr> EOT; echo '999999';//This line is the last additional statement to satisfy the precautions
Summarize
This is the article about the use and precautions of PHP delimiter. For more related content on the use and precautions of PHP delimiter, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!