🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1. ~~~ public function img_url($content){ if (preg_match('/(http:\/\/)|(https:\/\/)/i', $content)) { $url = ""; }else{ $url = "https://" . $_SERVER['SERVER_NAME']; } $pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/"; $list = preg_replace($pregRule, '<img src="' . $url . '${1}" style="max-width:100%">', $content); return $list; } ~~~ 2. ~~~ public function img($article){ $article['content'] = htmlspecialchars_decode($article['content']); //html实体转标签 preg_match_all('/(?<=img.src=").*?(?=")/', $article['content'], $out, PREG_PATTERN_ORDER); //正则匹配img标签的src属性,返回二维数组 if (!empty($out)) { foreach ($out as $v) { foreach ($v as $j) { $url = "https://wenlv.henan100.com".$j; $article['content'] = str_replace($j, $url, $article['content']); //替换相对路径为绝对路径 } } } } ~~~ 3. ~~~ if (!preg_match('/(http:\/\/)|(https:\/\/)/i', $data['thumbnail'])) { $data['thumbnail']=$host.$data['thumbnail']; } ~~~