PHP去除文章的html格式
来源:互联网 发布:算法分析与设计 王晓东 编辑:程序博客网 时间:2024/05/16 02:41
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;}
0 0
- PHP去除文章的html格式
- PHP清除html格式,去除html、css、js格式-函数代码
- php里去除html标记的函数
- php里去除html标记的函数
- PHP 去除多余的HTML标签
- php去除HTML标记
- PHP 去除HTML标签
- 去除HTML格式 截取字符串
- asp.net 去除HTML格式
- 去除字符串中的html格式
- 用C#去除字符串中HTML的格式
- 用C#去除字符串中HTML的格式
- PHP strip_tags()去除HTML、XML以及 PHP 的标签
- PHP去除html的宽高属性的正则表达式
- php如何清除html格式并去除文字中的空格然后截取文字
- php去除html中的script
- PHP去除html、css、Js
- PHP如何去除HTML标签
- Valgrind的用法
- Android
- PHP用isset替换count之优化
- ext 不错的入门
- 初学Angular+webpack+bootstrap
- PHP去除文章的html格式
- 代码规范文档学习笔记
- 使用Ngrok免注册版将内网项目发布到外网上(Windows系统下)
- Struts2中的ModelDriven机制及其运用
- Spring Boot 学习22--导入XML配置
- Activity C中关闭Activity A的方法
- 第一篇博客
- MySQL
- 转 A 、B两张表,找出ID字段中,存在A表,但是不存在B表的数据