博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php截取富文本img标签的src属性
阅读量:3919 次
发布时间:2019-05-23

本文共 767 字,大约阅读时间需要 2 分钟。

/** * 对富文本信息中的数据 * 匹配出所有的  标签的 src属性 * @param string $contentStr 富文本字符串 * @return array * */function getPatternMatchImages($contentStr = ""){    $imgSrcArr = [];    //首先将富文本字符串中的 img 标签进行匹配    $pattern_imgTag = '/
|\/>)/i'; preg_match_all($pattern_imgTag, $contentStr, $matchIMG); if (isset($matchIMG[0])) { foreach ($matchIMG[0] as $key => $imgTag) { //进一步提取 img标签中的 src属性信息 $pattern_src = '/\bsrc\b\s*=\s*[\'\"]?([^\'\"]*)[\'\"]?/i'; preg_match_all($pattern_src, $imgTag, $matchSrc); if (isset($matchSrc[1])) { foreach ($matchSrc[1] as $src) { //将匹配到的src信息压入数组 $imgSrcArr[] = $src; } } } } return $imgSrcArr;}

转载地址:http://bahrn.baihongyu.com/

你可能感兴趣的文章
Leetcode 60. 排列序列
查看>>
Leetcode 77. 组合
查看>>
Leetcode 74. 搜索二维矩阵
查看>>
Leetcode 86. 分隔链表
查看>>
Leetcode 92. 反转链表 II
查看>>
Leetcode 88. 合并两个有序数组
查看>>
Leetcode 89. 格雷编码
查看>>
Leetcode 67. 二进制求和
查看>>
Leetcode 69. x 的平方根
查看>>
进程、线程与协程
查看>>
Mysql中数据库引擎 INNODB
查看>>
模式1. 简单工厂模式-Java
查看>>
Leetcode 97. 交错字符串
查看>>
Leetcode 26. 删除有序数组中的重复项
查看>>
Leetcode 80. 删除有序数组中的重复项 II
查看>>
python字典赋初值
查看>>
error while loading shared libraries: lib.so.5000“ 错误的原因和解决办法
查看>>
shell 替换文件中的某个字符串
查看>>
ubuntu安装apache2
查看>>
网站实现高并发的方案
查看>>