Usage of Heredoc in PHP

Source: Internet
Author: User
Tags closing tag opening and closing tags
This article mainly introduces the use of Heredoc in PHP, has a certain reference value, now share to everyone, the need for friends can refer to

Heredoc technology, usually not detailed in regular PHP documentation and technical books, just mentions that this is a Perl-style string output technique.
But now some of the forum procedures, and some of the article system, are clever use of heredoc technology, to partially realize the interface and code of the quasi-separation, phpwind template is a typical example.

<?php$name = ' world Test '; Echo <<<EOT 

1. Start with a <<<end start tag, end With end tag, end tag must be written in the head, no indentation and space, and a semicolon at the end of the closing tag. The start tag is the same as the start tag, such as the usual uppercase EoT, EOD, EOF, but not limited to those, as long as the start tag and end tag are not present in the body.
2. 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.
3.heredoc is often used when the output contains a lot of HTML syntax and documentation. For example:

<?php$v = 123456; $a = <<<eof "abc" $v "123" Eof;echo $a; The result is output together with double quotes: "abc" 123456 "123"?>

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

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.