Delimiter echo<<< in PHP
Release: 2016-07-30 13:30:27
Original
1518 people have browsed it
Since PHP is a Web programming language, you will inevitably encounter the situation of using echo to output large sections of html and javascript scripts during the programming process. If you use the traditional output method-output by string, there must be a large number of The escape character is used to escape special characters such as quotation marks in the string. To avoid grammatical errors, we quote the delimiter "<<<".
1. The function of PHP delimiter is to output the things inside it as it is, including newline format and so on;
2. Any of the PHP delimiters Special characters do not need to be escaped;
3. PHP variables in the PHP delimiter will be replaced with their values normally.
Writing format:
echo << xxx;
where: 1. xxx should meet the requirements for variable names and can be in Chinese;
2. It must exist in an independent line; The delimiter format in PHP is as follows:
There are many places to pay attention to. First of all, the character Eof after <<< is self-defined. Anything is fine, but the characters at the end must be the same. They appear in pairs, like {} ——This is the most basic. In the process of using PHP delimiters, the second issue that needs attention is also the most common place where problems occur: The line at the end (such as Eof; in the above example) must be started on a new line and changed to another line. There cannot be any other characters except Eof; this delimiter ending identifier, neither before nor after, including spaces. If spaces or tabs appear at the beginning or end of the line, you will receive an error message like this: Parse error: parse error, unexpected $end in..., prompting you for a syntax error; The third requirement Note that if a PHP variable appears in the middle of the delimiter, you only need to write it as you would in other strings, for example:
<< hello{$name}
Eof;The reason why the variable $name is enclosed in {} is to tell the PHP parser that this is a PHP variable. In fact, it is okay not to use it, but There may be ambiguities. For example, what happens if your variable does not have a letter or special symbol after it? Never write it like this:
<<
helloEof;
In this case, you will also receive a syntax error message. Here is the correct way to write the PHP delimiter that has been tested. It contains the code of HTML and JavaScript: & & lt ;? PHP
$ name = 'kitty';
echo & lt; & lt; eoF
var p='hello world'; document.writeln (p); |
Eof;
?>
Reprinted Website: http://blog.sina.com.cn/s/blog_6d09b5750100w9we.html
The above introduces the delimiter echo
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31