Home > Backend Development > PHP Problem > How to use php delimiter

How to use php delimiter

(*-*)浩
Release: 2023-02-25 20:56:01
Original
2764 people have browsed it

Delimiter

How to use php 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;
?>
Copy after login

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;
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template