通过百度编辑器或其他富文本编辑器在后台上传内容。接口返回给前端是不带域名的,所以需要处理里面的图片。
/**
* 给ueditor 图片加上https
*/
function replaceUeditorImage ($content){
preg_match_all('/<img.*?src="(.*?)".*?>/is',$content,$array);
$newContent = $content;
foreach($array[1] as $k => $v){
$preg = "/^http(s)?:\\/\\/.+/";
if(!preg_match($preg,$v)){
$newContent = str_replace($v,urlhttps($v),$newContent);
}
}
return htmlspecialchars_decode($newContent);
}
/**
* 图片加https域名
* @param $url
* @return string
*/
function urlhttps($url){
if(!empty($url)){
$url = 'http://'.$_SERVER['HTTP_HOST'].$url;
}
return $url;
}