Three ways to add HTML code to PHP

Source: Internet
Author: User

Add HTML code to PHP, which is the PHP type of file to add HTML code ~

The first is to add PHP to the HTML.

Large segment of the HTML code, in each need to execute PHP <?php ...? >

such as line7-9:

1  2     <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8"/> 3     <meta http-equiv= "Content-language" content= "ZH-CN"/> 4     <title>hello world</title> 5  6 <body> 7     <?  PHP  8     echo "Hello world! This is the text"; 9     ? > </body> 

The second uses echo to output HTML.

Because there are double quotes in the HTML element, the contents of the echo output are enclosed in single quotes, avoiding errors and escaping this step . For example, this code:

1<?PHP2     if(!$_post){3     Echo‘<form action= "" method= "post" >4 server address: <input type= "text" name= "host" value= "localhost"/><br/>5 Database account: <input type= "text" name= "user" value= "/><br/>6 Database Password: <input type= "password" name= "pwd" value= "/><br/>7 Specify database: <input type= "text" name= "DB" value= "test"/><br/>8 <input type= "Submit" value= "OK"/>9</form> ';Ten     } One?>

Or this type of escape symbol is added:

1 <? PHP 2     Echo "<input type=\" submit\ "value=\" OK \ "/>" ; 3 ?>

The third is to use the (<<<) marker, which was first seen in PHP168 's template code.

1<?PHP2     Print<<<EOT3<divclass= "Slidecont" >{$label[Deepblue_mainslide]} </div>4<divclass= "Newcontainter" >5<divclass= "Head" >{$label[DEEPBLUE_MAINH1]} </div>6<divclass= "cont" id= "TAB1" >{$label[Deepblue_maint1]} </div>7<divclass= "cont" id= "TAB2" >{$label[Deepblue_maint2]} </div>8</div>9<a href= "$rs[url] "title="$rs[Descrip] "target=" _blank ">$rs[name]</a>Ten EOT; One?>

"<<<eot" and "EOT;" 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 .

However, there is one more thing to note when using the (<<<EOT) marker: The end-of-identifier string is EOT; To monopolize a row, there is no more content before and after, otherwise this PHP file is equivalent to obsolete.

Three ways to add HTML code to 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.