例如 $content='<p><img src="/uploads/image/20200818/1597720891186314.png" title="1597720891186314.png" alt="score1.png"/></p><p> <video class="edui-upload-video vjs-default-skin video-js" controls="" preload="none" width="420" height="280" src="/uploads/video/20200818/1597720911477773.mp4" data-setup="{}"></video></p>'; 要替换成带域名的路径 /** * 在富文本编辑器中 获得图片 返回全路径数组 */ public static function getContentImg($content,$oriweb='http://sxkj.cn'){ //匹配图片的src preg_match_all('#.*?src="([^"]*)"[^>]*>#i', $content, $match); foreach($match[1] as $imgurl){ $imgurl = $imgurl; if(is_int(strpos($imgurl, 'http'))){ $arcurl = $imgurl; } else { $arcurl = $oriweb.$imgurl; } $content=str_replace($imgurl,$arcurl,$content); } return $content; } 得到的结果如下 <p><img src="http://sxkj.cn/uploads/image/20200818/1597720891186314.png" title="1597720891186314.png" alt="score1.png"/></p> <p><video class="edui-upload-video vjs-default-skin video-js" controls="" preload="none" width="420" height="280" src="http://sxkj.cn/uploads/video/20200818/1597720911477773.mp4" data-setup="{}"></video></p>