2013-03-01 69 views
1

是否有像htmlentities或htmlspecialchars功能将转换特殊字符(&quot;)或你有什么,同时保留<br>,<span> .etc用户输入的数据后?功能特殊字符

+0

打印后使用html_entity_decode之前(字符串)将其再次更改为HTML – Vineet1982 2013-03-01 05:24:12

回答

0

有两种方式来获得所需要的东西:

<?php 

     $str = "<p>this -&gt; &quot;</p>\n"; 

     //Encoding 
     $encoded = htmlentities($str); 

     //Decoding note that here the quotes aren't converted 
    echo htmlspecialchars_decode($encoded, ENT_NOQUOTES); 
?> 

如果你想保存在数据库中的条目,因为它们使用addslashes的存储,因为它是

0

我希望你可以搜索htmlspecialchars_decode()

一个例子如下。

<?php 
$str = "<p>this -&gt; &quot;</p>\n"; 

echo htmlspecialchars_decode($str); 

// note that here the quotes aren't converted 
echo htmlspecialchars_decode($str, ENT_NOQUOTES); 
?> 

Php.net link