html批量去标签,PHP_php 批量替换html标签的实例代码,1.把html元素全部去掉,或者保 - phpStudy...

php 批量替换html标签的实例代码

1.把html元素全部去掉,或者保留某几个html标签

$text = '

Test paragraph.

Other text';

echo strip_tags($text);

echo "/n";

// Allow

and

echo strip_tags($text, '

');

?>

结果为(去掉了注释):

Test paragraph. Other text

Test paragraph.

Other text
2.相反,只去掉某一个html标签

function strip_only($str, $tags, $stripContent = false) {

$content = '';

if(!is_array($tags)) {

$tags = (strpos($str, '>') !== false ? explode('>', str_replace('

if(end($tags) == '') array_pop($tags);

}

foreach($tags as $tag) {

if ($stripContent)

$content = '(.+'.$tag.'[^>]*>|)';

$str = preg_replace('#?'.$tag.'[^>]*>'.$content.'#is', '', $str);

}

return $str;

}

$str = 'red text';

$tags = 'font';

$a = strip_only($str, $tags); // red text

$b = strip_only($str, $tags, true); // text

?>相关阅读:

解析Mysql备份与恢复简单总结与tee命令的使用介绍

Win10 Build 9926删除开始按钮下的磁贴应用的方法

php使用百度天气接口示例

jQuery常用数据处理方法小结

C#实现窗口之间的传值

举例讲解jQuery中可见性过滤选择器的使用

整理HTML5中支持的URL编码与字符编码

MySQL批量插入数据脚本

Jquery对象和Dom对象的区别分析

Win10正式版10586.75累积更新将很快推送

C#查找对象在ArrayList中出现位置的方法

C++线程池的简单实现方法

全面解析JavaScript里的循环方法之forEach,for-in,for-of

mysql服务性能优化—my.cnf_my.ini配置说明详解(16G内存)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值