编辑器内容返回给前端,图片无法显示的问题。

/**
 * 给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;
}

 

posted @ 2023-05-12 10:18  安语未  阅读(12)  评论(0编辑  收藏  举报