php php字符串转html
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4267232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php string convert to html
提问by Val
I have a string <div id="myid">
...</div>
我有一个字符串<div id="myid">
...</div>
How would I change this into
<div id="myid">
...</div>
怎么改成
<div id="myid">
……</div>
I have tried a few things but no luck any help?
我已经尝试了一些东西,但没有任何帮助?
Update
更新
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
FIX
使固定
function get_page(){
$file = 'file.php';
$str = file_get_contents($file);
return $str;
}
$output = get_page();
echo html_entity_decode($output);//works
回答by Pekka
The function for that is htmlspecialchars_decode()
.
其功能是htmlspecialchars_decode()
。
Note that for the function to decode quotes, you need to specify the $quote_style
parameter.
请注意,对于解码引号的函数,您需要指定$quote_style
参数。
回答by Yeroon
html_entity_decode
is what you need: http://www.php.net/manual/en/function.html-entity-decode.php
html_entity_decode
是你需要的:http: //www.php.net/manual/en/function.html-entity-decode.php
回答by user3124235
use this it's better ...
用这个更好...
<?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>');
?>
回答by PeeHaa
htmlspecialchars_decode($string)
回答by Napas
$from = array('<', '>');
$to = array('<', '>');
$string = str_replace($from, $to, $string);