/**

* 对 HTML 进行编码

* @param string $html 未编码的 HTML

* @return string 返回编码后的字符串

*/

public static function htmlEncode($html) {

return get_magic_quotes_gpc() ? htmlspecialchars($html) : htmlspecialchars(addslashes($html));

}

该方法是将<p>进行编码</p> 转换成&lt;p&gt;进行编码&lt;/p&gt;gt;


/**

* 对 HTML 进行解码

* @param string $data 已编码的 HTML

* @return string 返回解码后的字符串

*/

public static function htmlDecode($data) {

return get_magic_quotes_gpc() ? htmlspecialchars_decode($data) : stripslashes(htmlspecialchars_decode($data));

}

该方法是将&lt;p&gt;进行编码&lt;/p&gt;gt; 转换成 <p>进行解码</p>


php内置方法 strip_tags(); 过滤html标签 和php标记.


strip_tags() 与 htmlDecode() 结合使用只剩下纯文本.