2013-03-01 120 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