php将富文本内容图片上传到oss并替换

/**
 * php 提取html中图片并替换
 */
//要替换的内容
//提取图片路径的src的正则表达式
$match_str = '/(<img([^>]*)\s*src=(\'|\")([^\'\"]+)(\'|\")|url.*\(https:.*=png\))/';
preg_match_all($match_str,$content,$matches);

if (!empty($matches)){
    $http_str= '/http.*(png|jpeg|jpg|gif|bmp)/';
    foreach ($matches[0] as $k=>$v){
      preg_match($http_str,$v,$http);
      //去上传 获得上传后的链接
      $upload_url = "";
      if (!empty($http[0])){
          $content= str_replace($http[0],$upload_url,$content);
      }
      //获得链接后替换

    }
}

echo $content;
posted @ 2020-01-15 14:08  phpwyl  阅读(491)  评论(0编辑  收藏  举报