php过滤html标签函数

/**
* 过滤html标签
* @param string $string 要过滤的字符串,可用于ueditor编辑器此方法
* @param string $tags	要保留的html标签,可写多个,如<img><p>
*/
strip_tags($string,'<img><p>');


html字符实体,转义字符(&nbsp; &gt; &lt; )

http://www.w3school.com.cn/html/html_entities.asp

显示结果描述实体名称实体编号

空格&nbsp;&#160;
<小于号&lt;&#60;
>大于号&gt;&#62;
&和号&amp;&#38;
"引号&quot;&#34;
'撇号 &apos; (IE不支持)&#39;
&cent;&#162;
£&pound;&#163;
¥日圆&yen;&#165;
欧元&euro;&#8364;
§小节&sect;&#167;
©版权&copy;&#169;
®注册商标&reg;&#174;
商标&trade;&#8482;
×乘号&times;&#215;
÷除号&divide;&#247;


// 过滤html标签中的属性
$ret = preg_replace(
	array(
		// 匹配标签中的 style="" 属性
		// "/(<\w+)\s+(style=\".*?\")\s*(>)/i",
		// 匹配标签中的所有属性
		"/(<\w+)\s+(.*?)\s*(>)/i",
	),
	array(
		'\1\3',
	),
	$str
);

echo $ret;