PHP convert html  到空间, >到>等

2022-08-30 22:48:10

我想将所有html标签(&nbsp &gt&gt&lt等)转换为文本格式;我试过了

html_entity_decode() 

但它会回来?if &nbsp.


答案 1

使用与 相反。
PHP 文档页面中的示例:htmlspecialchars_decodehtmlspecialchars

    $str = '<p>this -&gt; &quot;</p>';
    echo htmlspecialchars_decode($str); 
    //Output: <p>this -> "</p>

答案 2

html_entity_decode()htmlentities() 相反,因为它将字符串中的所有 HTML 实体转换为其适用的字符。

$orig = "I'll \"walk\" the <b>dog</b> now";

$a = htmlentities($orig);

$b = html_entity_decode($a);

echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b; // I'll "walk" the <b>dog</b> now

推荐