Instructions for using PHP EOF(heredoc)

jacklove
Release: 2023-03-25 14:52:02
Original
2081 people have browsed it

PHP EOF (heredoc) is a method defined in command line shells (such as sh, csh, ksh, bash, PowerShell and zsh) and programming languages ​​(such as Perl, PHP, Python and Ruby) A string method.

Usage overview:

1. It must be followed by a semicolon, otherwise the compilation will not pass.

2. EOF can be replaced by any other characters, as long as the end identifier is consistent with the start identifier.

3. The end mark must occupy a line by itself at the top of the line (that is, it must start from the beginning of the line, and cannot be connected with any blanks or characters before and after).

4. The start mark can be without quotation marks or with single or double quotation marks. The effect of without quotation marks is the same as that with double quotation marks. Interpret the embedded variables and escape character sign, with single quotation marks. Embedded variables and escape symbols are not interpreted.

5. When the content requires embedded quotes (single quotes or double quotes), there is no need to add escape characters. Single and double quotes are escaped by itself. This is equivalent to the usage of q and qq.

Example

<?phpecho <<<EOF
    <h1>我的第一个标题</h1>
    <p>我的第一个段落。</p>EOF;// 结束需要独立一行且前后不能空格?>
Copy after login

Note:

1. Start with <<

2. The start tag and the end tag are the same, such as commonly used uppercase EOT, EOD, EOF, but not limited to those (can also use: JSON, HTML, etc.), as long as the start tag and end tag are ensured The markup does not need to appear in the text.

3. Variables located between the start tag and the end tag can be parsed normally, but functions cannot. In heredoc, variables do not need to be spliced ​​with connectors. or,, as follows:

Example

<?php$name="runoob";$a= <<<EOF
    "abc"$name
    "123"EOF;// 结束需要独立一行且前后不能空格echo $a;?>
Copy after login

This article explains the usage instructions of PHP EOF (heredoc) in detail, and more Please follow the php Chinese website to view the learning materials.

Related recommendations:

About PHP loops - Detailed explanation of For loop

About PHP If...Else statement Operation usage

#Related explanations about PHP 5 data types

The above is the detailed content of Instructions for using PHP EOF(heredoc). 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