Summary of Heredoc application in PHP

Source: Internet
Author: User
Tags closing tag opening and closing tags
Summary of PHP Heredoc usage
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

For example

 
    
 
  Untitled Document   
 
  Hello, $name!  EOT;? >


I. end tag with <> << must be written by the head. You cannot have indents and spaces, and you have a semicolon at the end of the closing tag. The start tag and the start tag are the same, For example, EOT, EOD, EOF are commonly used in uppercase, but not limited to those, as long as the opening and closing tags do not appear in the body.


twoBetween the opening and closing tags. variables can be parsed normallyBut function is not allowed。 In Heredoc, a variable does not need a connector. Or, to splice。

For example
 $v =2; $a = << 
   
   
)
three . Heredoc is often used when the output contains a large number of HTML syntax D documents. For example: function outputhtml () to output the HTML home page. There are two ways to do this. Obviously the second is simpler and easier to read.

function outputhtml () {echo ""; echo " home "; echo "homepage content"; echo ";} function outputhtml () {echo << 
     
      home page  home page content eot;}
   Outputhtml (); 
     

  • 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.