去除内容多余样式php函数
PHP 函数 内容 样式 去除 多余
2023-09-14 08:57:34 时间
今天给客户做百度小程序,出现数据库里面有多余的样式,比如style=""里面内容,小程序前端又不好过滤,又不能去数据库里面替换,只能后端过滤多余样式进行排版。
代码附上:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
function KillStyle( $content ) { $content = preg_replace( "/STYLE=.+?['|\"]/i" ,'', $content ); //去除样式 $content = preg_replace( "/style=.+?['|\"]/i" ,'', $content ); //去除样式 $content = preg_replace( "/class=.+?['|\"]/i" ,'', $content ); //去除样式 $content = preg_replace( "/id=.+?['|\"]/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 参数 $content = preg_replace( "/<a[^>]*>/i" , "" , $content ); $content = preg_replace( "/<\/a>/i" , "" , $content ); $content = preg_replace( "/<div[^>]*>/i" , "<p>" , $content ); $content = preg_replace( "/<\/div>/i" , "</p>" , $content ); $content = preg_replace( "/<h1[^>]*>/i" , "<strong>" , $content ); $content = preg_replace( "/<\/h1>/i" , "</strong>" , $content ); $content = preg_replace( "/<h2[^>]*>/i" , "<strong>" , $content ); $content = preg_replace( "/<\/h2>/i" , "</strong>" , $content ); $content = preg_replace( "/<h3[^>]*>/i" , "<strong>" , $content ); $content = preg_replace( "/<\/h3>/i" , "</strong>" , $content ); $content = preg_replace( "/<table[^>]*>/i" , "<table>" , $content ); $content = preg_replace( "/<!--[^>]*-->/i" , "" , $content ); //注释内容 $content = preg_replace( "/<p[^>]*>/i" , "<p>" , $content ); $content = preg_replace( "/<span[^>]*>/i" , "<p>" , $content ); $content = preg_replace( "/<\/span>/i" , "</p>" , $content ); $content = preg_replace( "/<(script.*?)>(.*?)<(\/script.*?)>/si" , "" , $content ); //过滤script标签 $content = preg_replace( "/<(em.*?)>(.*?)<(\/em.*?)>/si" , "" , $content ); //过滤script标签 return $content ; } |
相关文章
- 数据PHP实现MySQL数据导出的实现方法(php导出mysql)
- 完美安装:PHP环境下实现Redis扩展(php安装redis扩展)
- MySQL实现PHP数组存储的效果(mysql存储数组php)
- 坚持不懈:用PHP实现MSSQL数据库连接(php链接mssql函数)
- PHP.MVC的模板标签系统(三)
- php数据库连接
- 谈谈新手如何学习PHP
- php查看session内容的函数
- php下实现在指定目录搜索指定类型文件的函数
- PHP中的MYSQL常用函数(php下操作数据库必备)
- php入门学习知识点三PHP上传
- php数组函数序列之rsort()-对数组的元素值进行降序排序
- PHP求小于1000的所有水仙花数的代码
- php实现快速排序法函数代码
- PHP代码保护--ZendGuard的使用详解
- 探讨如何在PHP开启gzip页面压缩实例
- php常用Output和ptions/Info函数集介绍
- 解析PHP中ob_start()函数的用法
- PHP获取和操作配置文件php.ini的几个函数介绍
- php获取网页标题和内容函数(不包含html标签)
- 实现获取http内容的php函数分享
- PHP图片裁剪函数(保持图像不变形)
- php导出csv格式数据并将数字转换成文本的思路以及代码分享
- php+ajax实现图片文件上传功能实例