php正则取html所有图片src地址

/**
 * 获取替换文章中的图片路径
 * @param string $xstr 内容
 * @param string $keyword 创建照片的文件名
 * @param string $oriweb 网址
 * @return string
 * 
 */
  
public function replaceimg(){ 
    $data = $this->request->param();
    $xstr=$data['post']['author'];
  	//var_dump($xstr);
    $oriweb='https://admin.tstvip.cn';
    $post = $data['post'];  

    //匹配图片的src
    $pattern="/<img.*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/";

  preg_match_all($pattern,htmlspecialchars_decode($xstr),$match);
  	//var_dump($match);
  
    foreach($match[1] as $imgurl){
       
        $imgurl = $imgurl;
        
        if(is_int(strpos($imgurl, 'http'))){ //这里可以通过字符串筛选要下载的图片
            $arcurl = $imgurl;
        } else {
            $arcurl = $oriweb.$imgurl;        
        }
        $img=file_get_contents($arcurl);
        
        if(!empty($img)) {
        
            //保存图片到服务器
            $fileimgname = time()."-".rand(1000,9999).".jpg";
            $filecachs=$_SERVER['DOCUMENT_ROOT'].'/upload/'.$fileimgname;
            $fanhuistr = file_put_contents( $filecachs, $img );
            $saveimgfile =$oriweb. "/upload/".$fileimgname;   
            $xstr=str_replace($imgurl,$saveimgfile,$xstr);
            
        }
    }
  echo $xstr;
}