Three ways to Mash PHP

Source: Internet
Author: User
In W3school to school PHP, see the first sentence is "PHP files can contain text, HTML tags and scripts"


later in the study of other people's Code, found in the need for HTML code in the PHP script, the use of such several methods
First Kind is to add PHP to the HTML. Large sections of HTML code, where PHP is required to execute . This method is more common in ASP programs.
Example:
[Code_lite]



Hello World


echo "Hello world! This is the text";
?>
[/code_lite]
The second Kindoutput HTML with echo. However, there are double quotes in the HTML, and the contents of the echo output are enclosed in single quotes, avoiding errors and escaping this step. For example, this code:
[Code_lite]

if (!$_post)
{
Echo ' Description
';
}
? >[/code_lite]
but more than most of the more visible or add the escape symbol, the individual feel uncomfortable reading
[Code_lite]echo]"[/code_lite]
Third Kindis to use the (<<<) marker, which was first seen in PHP168 's template code.
[code_lite]<<
EOT; [/code_lite]
In the middle of the document output directly, a better understanding of the saying is "a multi-line echo."
The advantage is that the output of large pieces of HTML is convenient, does not need to be escaped, and can reference variables. An example:
[Code_lite]
!--? PHP
print <<
{$label [deepblue_mainslide]}

{$label [deepblue_mainh1]}

{$label [deepblue_maint1]}


{$label [Deepblue_maint2]}


$rs [name]
EOT;
? >[/code_lite]
The above example cleanly output the value of the large segment html+ variable, very good.
Note: You can use the EOT mode output multiple times, but <<

The above describes the PHP mixed three ways, including aspects of the content, I hope that the PHP tutorial interested in a friend to help.

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