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);
?>输出:
云耀云服务器价格说明从阳澄湖大闸蟹来看看生鲜电商的发展adobe flash player是什么?阿里云服务器和本地虚拟机区别大吗内蒙云服务器租用多少钱轻量云服务器可以挂游戏吗服务器挂云上如何管理阿里云服务器香港优惠