What are the Heredoc and Nowdoc in PHP

Source: Internet
Author: User

The HEREDOC structure resembles a double-quote string, and the Nowdoc structure is similar to a single-quote string. The NOWDOC structure is much like the heredoc structure, but Nowdoc does not perform parsing operations. This structure is well suited for use in PHP code and other large pieces of text that do not need to be escaped. And the <! of SGML [cdata[]]> structure is used to declare a large segment of the text like no parsing, nowdoc structure has the same characteristics.
A NOWDOC structure is also labeled <<< with the same heredocs structure, but the following markers are enclosed in single quotes, like the <<< ' EOT '. All rules of the HEREDOCS structure also apply to the NOWDOC structure, especially the rule of the end marker.
Take a look at the following examples of Heredoc:

$name= "Jbilder"; $age= "18"; $title= "jbilder_9986"; Echo "Here is the use of Heredoc: <br/>"; echo <<<jbilderphp How to solve the session when the custom session is covered??? My nameis: {$name}; Age: {$age}; Title: {$title}. jbilderphp;

The resulting results are:


Take a look at the following examples of Nowdoc:

1 $name= "Jbilder"; $age= "18"; $title= "jbilder_9986"; 2 Echo "Here is the use of Heredoc: <br/>"; 3 echo <<<jbilderphp4 How to fix the session when the custom session is covered??? My name is: {$name}; Age: {$age}; Title: {$title}. 5 jbilderphp;
View Code

The resulting results are:

Note that for Heredoc variables to be enclosed in curly braces, if you write directly as follows:

1 echo <<< ' jbilderphp '2 How to fix the session when a custom session is covered??? My name is:$name; Age:$age; title:$title. 3 jbilderphp;
View Code

You will receive the following prompt error:

What are the Heredoc and Nowdoc in PHP

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.