富文本编辑器中替换img的src属性由相对路径替换为绝对路径

foreach($res as $k => $v){
  
$res[$k]['content'] = htmlspecialchars_decode($v['content']);     //html实体转标签
preg_match_all('/(?<=img.src=").*?(?=")/', $res[$k]['content'], $out, PREG_PATTERN_ORDER); //正则匹配img标签的src属性,返回二维数组
if (!empty($out)) {
foreach ($out as $v) {
foreach ($v as $j) {
$url = "https://".$_SERVER['SERVER_NAME'].$j;
$res[$k]['content'] = str_replace($j, $url, $res[$k]['content']); //替换相对路径为绝对路径
}
}
}
}
posted @ 2019-04-02 11:40  没有感情的机器  阅读(...)  评论(...编辑  收藏