可以使用htmlentities函数
<?phpheader("content-type:text/htmlcharset=utf-8")
$str = '<a href="http://www.baidu.com">百度一下</a>'
echo htmlentities($str)
?>
输出结果
<a href="http://www.baidu.com">百度一下</a>其实很简单,只要把html语句中的双引号改为单引号,然后直接用echo输出就行了:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<ul class="nav navbar-nav navbar-right">
<li class="nli"><a href="/About/">关于我们</a></li>
<li class="nli"><a href="/Notice/">舞蹈</a></li>
<li class="nli"><a href="/Instructors/">师资阵容</a></li>
</li></ul>
<?php
echo("<ul class='nav navbar-nav navbar-right'>")
echo("<li class='nli'><a href='/About/'>关于我们</a></li>")
echo(" <li class='nli'><a href='/Notice/'>舞蹈</a></li>")
echo(" <li class='nli'><a href='/Instructors/'>师资阵容</a></li>")
echo("</li></ul>")
?>
</body>
</html>
<?phpfunction savefile($path,$type="w",$content){
if($fopen=@fopen($path,$type)){
@fwrite($fopen,$content)
return $fopen
@fclose($fopen)
}
}
savefile("路径/1.html","w","PHP输出的内容")
?>