本文共 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/