Home > Backend Development > PHP Tutorial > A brief discussion on the <<< operator in PHP_php skills

A brief discussion on the <<< operator in PHP_php skills

WBOY
Release: 2016-05-16 19:53:55
Original
1145 people have browsed it

PHP provides the <<< operator to construct a multi-line string sequence, usually called a here-document or expressed as the abbreviation of heredoc.

This method elaborates the literal value of the string and preserves the string's underscores and other whitespace (including indentation) in the text. For example:

<&#63;php
$author ='wixy';
echo <<<_END
Thisis a Headline
Thisis the first line.
Thisis the second line.
---Writtenby $author.
_END;
&#63;>

Copy after login

The PHP parser will output all the content between the two _END tags, which is equivalent to a string quoted in double quotes.
This means that we can write an entire section of HTML language directly in PHP code, and then use PHP variables to replace the specific dynamic parts.

 <&#63;php
 $out =<<<_END
 .....
 _END;
 &#63;>

Copy after login

You can also use the above method to assign the contents of the two tags to variables.

Note: The _END tag used to close must be placed on a separate line, and no other content can be added to this line, even comments or spaces are not allowed

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