Home > Article > Backend Development > Three ways to embed html code in php programs
The three methods for embedding html code into php programs are as follows:
The first is to add PHP
large sections of html to HTML In the code, in each place where php needs to be executed, 79184d89c68e7248f3e40700b013c63b
For example, line7-9:
1 <head> 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 </head> 6 <body> 7 <?php 8 echo "Hello world!这是正文"; 9 ?> 10 </body> 11 </html>
The second method uses echo to output HTML.
Because some HTML elements have double quotes, the content output by echo is enclosed in single quotes to avoid errors and save the escaping step. For example, code like this:
(Learning video sharing: php video tutorial)
<?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>‘; } ?>
Or this kind of code with escape symbols:
<?php echo "<input type=\"submit\" value=\"确定\"/>" ; ?>
The third way is to use the (<<<) tag, which was first seen in the template code of PHP168.
<?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 document between "<<
But there is one more thing to note when using the (<< The EOT tag here can be replaced with any tag, such as print << Related recommendations: php tutorial The above is the detailed content of Three ways to embed html code in php programs. For more information, please follow other related articles on the PHP Chinese website!