
PHP中嵌入HTML有多种方式,这里列出几种常用方式: 1、用echo输出HTML代码 <?php
$int=rand(0,1);
if($int==1){
echo "<p>取到的随机数是1</p>";
}else{
echo "<p>取到的随机数不是1</p>";
}
?> 2、HTML代码中嵌入PHP 这样可以在大段大段的html代码的各个需要执行php的地方添加<?php .... ?>代码了。 <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title>Hello World</title>
</head>
<body>
<?php
echo "Hello world!这是正文";
?>
</body>
</html> 3、使用(<<<)标记符
这是在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;
?> 4、直接引用HTML文件进PHP中
一个HTML文件(test.html),主要代码为: <body>
<p>我是一段Html代码</p>
</body> 使用php的include()函数将外部的HTML文件连接到PHP文件中 <?php
include ("test.html");
?> 输出:

以上就是php中怎么嵌入html代码的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |