Instructions on how to use PHP EOF (heredoc)

Source: Internet
Author: User
PHP EOF (Heredoc) is a method of defining a string in command-line shells such as sh, csh, ksh, Bash, PowerShell, and zsh, and programming languages such as Perl, PHP, Python, and Ruby.

Usage Overview:

1. The semicolon must be followed, otherwise the compilation will not pass.

2. EOF can be substituted with any other character, just to ensure that the end identity is consistent with the start identity.

3. The end identity must be shelf alone (i.e. must start at the beginning of the line, and cannot be connected to any whitespace and characters).

4. Start identification can be without quotation marks or with single double quotation marks, without quotation marks and with double quotes effect, interpreted inline variables and escape symbols, with single quotation marks does not explain the embedded variables and escape symbols.

5. When the content requires embedded quotation marks (single or double quotation marks), do not need to add escape character, itself to single double quotes escaped, here quite with the use of Q and QQ.

Instance

<?phpecho <<<eof    

Attention:

1. Start with the <<<eof start tag, end with the EOF end tag, the end tag must be written in the head, cannot have indents and spaces, and there should be a semicolon at the end of the tag.

2. The opening and closing tags are the same, such as EOT, EOD, EOF, which are commonly capitalized, but are not limited to those (which can also be used: JSON, HTML, etc.), as long as the start tag and end tag are not present in the body.

3. Variables located between the opening and closing tags can be parsed normally, but the function is not. In Heredoc, a variable does not need a connector. Or, to splice, as follows:

Instance

<?php$name= "Runoob"; $a = <<<eof    "abc" $name    "123" eof;//end requires a separate row and no space echo $a; >

This article explains in detail the use of the PHP EOF (heredoc), more learning materials to focus on the PHP Chinese network can be viewed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.