How to use php delimiters?
Usage of delimiter <<< in php
Delimiter
give The method of string delimitation uses delimiter syntax ("<<<"). An identifier should be provided after <<<, then the string, and then the same identifier terminating the string.
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.
Recommended: "PHP Tutorial"
For example:
<?php $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; ?>
But please note:
End identifier The line cannot contain any other characters, except perhaps a semicolon (;). In particular, this means that the identifier cannot be indented, and there cannot be any spaces or tabs before or after the semicolon.
It is also important to realize that the first character before the terminating identifier must be a newline character as defined in your operating system. For example, on Macintosh systems 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: Delimited text behaves the same as a double-quoted string, but without 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 1:
<?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; ?>
Example 2:
<? $xml=<<<EOT <message name="getTermRequest"> <part name="term" type="xs:string"/> </message> <message name="getTermResponse"> <part name="value" type="xs:string"/> </message> <portType name="glossaryTerms"> <operation name="getTerm"> <input message="getTermRequest"/> <output message="getTermResponse"/> </operation> </portType> EOT; echo $xml; ?>
The above is the detailed content of How to use php delimiters. For more information, please follow other related articles on the PHP Chinese website!