Home >Backend Development >PHP Tutorial >怎么将读入的html文件 输出为字符

怎么将读入的html文件 输出为字符

WBOY
WBOYOriginal
2016-06-13 11:49:201030browse

如何将读入的html文件 输出为字符!

本帖最后由 storylok 于 2014-01-09 23:20:42 编辑
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><title>无标题文档</title><br /></head><br /><br /><body><br /><?php<br />$DocumentRoot = $_SERVER['DOCUMENT_ROOT'];<br />$a = readfile("$DocumentRoot/index-1.html");<br />?><br /><textarea style="width:500px; height:300px;"><?php echo $a; ?></textarea><br /></body><br /></html>



我想让读入的html文件 输出的时候是显示标签 如何做到。现在的输出以后他是按照原义输出的。我使用下面的方法能正确显示。是不是readfile()函数不能作字符串输出?他会执行原型输出?

如果我使用 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><title>无标题文档</title><br /></head><br /><br /><body><br /><textarea style="width:500px; height:300px;"><br /><?php<br />$DocumentRoot = $_SERVER['DOCUMENT_ROOT'];<br />$a = fopen("$DocumentRoot/index-1.html",'rb');<br />while(!feof($a)){<br />	$aa = fgets($a,999);<br />	echo $aa;<br />	}<br />?></textarea><br /></body><br /></html>


------解决方案--------------------
<?php<br />$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);<br />echo $new;<br />?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn