PHP去除文章的html格式
2017-04-27 18:01
106 查看
function cutstr_html($string,$length=0,$ellipsis='…'){ $string=strip_tags($string); $string=preg_replace('/\n/is','',$string); $string=preg_replace('/ | /is','',$string); $string=preg_replace('/ /is','',$string); preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/",$string,$string); if(is_array($string)&&!empty($string[0])){ if(is_numeric($length)&&$length){ $string=join('',array_slice($string[0],0,$length)).$ellipsis; }else{ $string=implode('',$string[0]); } }else{ $string=''; } return $string; } function clearHtml($content) { $content = preg_replace("/<a[^>]*>/i", "", $content); @$content = preg_replace("/<\/a>/i", "", $content); $content = preg_replace("/<div[^>]*>/i", "", $content); @$content = preg_replace("/<\/div>/i", "", $content); $content = preg_replace("/<!--[^>]*-->/i", "", $content);//注释内容 $content = preg_replace("/style=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/class=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/id=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/lang=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/width=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/height=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/border=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/face=.+?['|\"]/i", '', $content);//去除样式 $content = preg_replace("/face=.+?['|\"]/", '', $content);//去除样式 只允许小写 正则匹配没有带 i 参数 return $content; }
相关文章推荐
- php如何清除html格式并去除文字中的空格然后截取文字
- php读取富文本编辑器编辑后的文章内容,并去除所有html标签、空格以及空白,截取字符串(包括中文)
- PHP清除html、css、js格式并去除空格的PHP函数
- php里去除html标记的函数 【转】
- php去除html中的script
- php去除HTML标记
- 关于含有HTML标签格式的文章截取功能实现
- 用于从SQL中读取去除格式样式的文章段
- php中去除所有js,html,css代码
- 去除HTML格式 截取字符串
- PHP分页、防止英文单词被截段、去除HTML代码
- php 去除html标记-strip_tags和htmlspecialchars的区别
- 用C#去除字符串中HTML的格式
- 用C#去除字符串中HTML的格式
- 将文本格式的文章转换为html/xml格式文本的功能封装到Javabean
- CuteEditor Html中显示Word格式粘贴的文章[CuteEditor WordToHtml]
- 去除html和php标记的方法--strip_tags
- C#中利用正则表达式去除HTML中的格式
- PHP 中如何去除 HTML 标签