in the 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
The first 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:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title>Hello World</title><style>body{font-size:15px;color:#000;font-family:Arial,Helvetica,sans-serif;}a{color:#039;text-decoration:none;}</style>
<?php
echo "Hello world!这是正文";
?>
</b></body>
The second uses Echo to output HTML. 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:
<?php
if(!$_POST)
{
echo ‘<form action="" method="post">
服务器地址:<input type="text" name="host" value="localhost" /><br />
数据库账号:<input type="text" name="user" value="" /><br />
数据库密码:<input type="password" name="pwd" value="" /><br />
指定数据库:<input type="text" name="db" value="test" /><br />
<input type="submit" value="确定"/>
</form>}
?>
But more than most of the more visible or add the escape symbol, the individual feel uncomfortable reading
echo "<input type=\"submit\" value=\"确定\"/>"
The third is to use the (<<<) marker, which was first seen in PHP168 's template code.
<<<EOT
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. An example:
<?php
Print <<<eot
<div class= "Slidecont" >{$label [deepblue_mainslide]}</div>
<div class= "Newcontainter" >
<div class= "Head" >{$label [deepblue_mainh1]}</div>
<div class= "cont" id= "TAB1" >
{$label [deepblue_maint1]}
</div>
<div class= "cont" id= "TAB2" >
{$label [Deepblue_maint2]}
</div>
</div>
<a href= "$rs [url]" title= "$rs [Descrip]" target= "_blank" > $rs [name]</a>
EOT;
?>
The above example cleanly output the value of a large segment of the html+ variable, very good.
but in use (<<<eot)
One more thing to note about markers: The end-of-identifier string is EOT;
A particularly easy mistake is to add spaces and indents to the identifier, and the following example will not output
<?php
print <<<EOT
<a href="http://blog.i1728.com/" title="东方天宇的博客">东方天宇的博客</a>
EOT;
echo "喂~人家在等你呢!";
?>
We will find that the last echo is not executed. This is because (<<<EOT)
The identifier end character is not found, and the Echo statement is also included in the content that needs to be entered.
At the same time, all content is not output because the identifier end character is not found.
Of course, this is only my understanding, because the script will not have content even if the Echo statement is placed in front of print <<.
For what reason, it is left to everyone to discuss.
Turn from http://blog.i1728.com/post/110.html.