原文网址:https://www.youyong.top/article/11595c6d9141d
PHP中有时也会涉及到对html内容的处理,去除一些标签样式之类的,下面就举例说明
原文网址:https://www.youyong.top/article/11595c6d9141d
PHP中有时也会涉及到对html内容的处理,去除一些标签样式之类的,下面就举例说明
原文网址:https://www.youyong.top/article/11595c6d9141d
用正则匹配去除。举例如下:
1:去除标签 a
$content = preg_replace("/<a[^>]*>/i", "", $content);
$content = preg_replace("/<\/a>/i", "", $content);
2:去除标签 div
$content = preg_replace("/<div[^>]*>/i", "", $content);
$content = preg_replace("/<\/div>/i", "", $content);
3: 去除 注释内容
$content = preg_replace("/<!--[^>]*-->/i", "", $content);//注释内容
4: 去除 标签属性 style id class lang width height face 等
$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);
共 0 条留言
Linux php-fpm报错:allow_call_time_pass_reference
6款程序员必备的开源中文汉字拼音转换及处理工具 (PHP Java .net)
PHP Fatal error: Allowed memory size of bytes exhausted
改了php.ini中的open_basedir仍报错open_basedir restriction in effect
php call_user_fun Call-time pass-by-reference has been remov
iPhone X 跌破发行价,苏宁200亿入股恒大 | 财经日日评
资深黄牛现身说法:iPhone X价格秒变不停,就像炒股一样
改了php.ini中的open_basedir仍报错open_basedir restriction in effect
推荐 | PHP WEB消息推送框架 web-msg-sender (PHPSocket.IO)
如何准确判断请求是不是搜索引擎爬虫(蜘蛛)发出的请求?(php window linux)
PHP Warning: feof() expects parameter 1 to be resource, null
手机扫一扫
分享文章