Home > Article > Backend Development > How to use php delimiter
Delimiter
The method of delimiting a string uses delimiter syntax (" <<<”). An identifier should be provided after <<<, then the string, and then the same identifier terminating the string. (Recommended learning: PHP video tutorial)
The end identifier must start from the first column of the row. Likewise, identifiers must follow the naming rules for any other tag in PHP: they must only contain alphanumeric underscores, and they must start with an underscore or a non-numeric character.
For example:
<?php $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; ?>
But please note:
ends the line where the identifier is located It cannot contain any other characters, except perhaps a semicolon (;). This means in particular that the identifier cannot be indented and there cannot be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline character as defined in your operating system.
For example, in Macintosh system it is \r. If you break this rule so that the end identifier is not "clean", it will not be considered an end identifier and PHP will keep looking for it. Failure to find a suitable closing identifier in this case will result in a syntax error on the last line of the script.
ps: The delimiter text behaves the same as a double-quoted string, but without the double quotes. This means that quotes do not need to be escaped within delimited text, but the escape codes listed above can still be used.
Example:
<?php echo <<< 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">学生姓名</td> <td align="center">家长姓名</td> <td align="center">家长手机号</td> </tr> EOT; ?>
The above is the detailed content of How to use php delimiter. For more information, please follow other related articles on the PHP Chinese website!