php字符串转换为html
我有一个字符串php字符串转换为html,php,character,Php,Character,我有一个字符串div id=“myid”…/div 我怎样才能把它变成 .. 我试过一些方法,但是运气不好。有什么帮助吗 更新 function get_page(){ $file = 'file.php'; $str = file_get_contents($file); $str = html_entity_decode($str); return $str; } $output = get_page(); echo $output;//don't work 修复 func
div id=“myid”
…/div
我怎样才能把它变成
..
我试过一些方法,但是运气不好。有什么帮助吗
更新
function get_page(){
$file = 'file.php';
$str = file_get_contents($file);
$str = html_entity_decode($str);
return $str;
}
$output = get_page();
echo $output;//don't work
修复
function get_page(){
$file = 'file.php';
$str = file_get_contents($file);
return $str;
}
$output = get_page();
echo html_entity_decode($output);//works
其功能是
请注意,对于解码引号的函数,需要指定$quote\u style
参数。$from=array(“”,”);
htmlspecialchars_decode($string)
$to=数组(“”);
$string=str_replace($from,$to,$string);
html\u entity\u decode
是您所需要的:使用它更好…
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
@Val您得到了什么结果?你用什么代码?您是这样使用它的:$string=htmlspecialchars\u decode($string)代码>,对吗?是的,和$str=htmlspecialchars\u decode($str,entnoquotes)代码>仍然不起作用。我使用fwrite
将它保存到一个文件中,然后我尝试将它输出到html,如果是这样的话,它将显示为纯文本而不是html元素helps@Val你的问题很可能在别处。尝试一个echo$str代码>要查看右侧的输出。。。注意我的更新,试着帮我找出哪里出了问题。问题出在返回$str
上,我可能会在这里呆上一年,试图找出所有单个字符,其次,这可能会降低页面速度,
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>