企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
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']; } ~~~