php过滤html标签函数strip_tags($str,'<img>')
来源:原创
时间:2016-07-22
作者:脚本小站
分类:PHP
php过滤html标签函数
/** * 过滤html标签 * @param string $string 要过滤的字符串,可用于ueditor编辑器此方法 * @param string $tags 要保留的html标签,可写多个,如<img><p> */ strip_tags($string,'<img><p>');
html字符实体,转义字符( > < )
http://www.w3school.com.cn/html/html_entities.asp
显示结果 | 描述 | 实体名称 | 实体编号 |
---|---|---|---|
空格 | |   | |
< | 小于号 | < | < |
> | 大于号 | > | > |
& | 和号 | & | & |
" | 引号 | " | " |
' | 撇号 | ' (IE不支持) | ' |
¢ | 分 | ¢ | ¢ |
£ | 镑 | £ | £ |
¥ | 日圆 | ¥ | ¥ |
€ | 欧元 | € | € |
§ | 小节 | § | § |
© | 版权 | © | © |
® | 注册商标 | ® | ® |
™ | 商标 | ™ | ™ |
× | 乘号 | × | × |
÷ | 除号 | ÷ | ÷ |
// 过滤html标签中的属性 $ret = preg_replace( array( // 匹配标签中的 style="" 属性 // "/(<\w+)\s+(style=\".*?\")\s*(>)/i", // 匹配标签中的所有属性 "/(<\w+)\s+(.*?)\s*(>)/i", ), array( '\1\3', ), $str ); echo $ret;