ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的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']; } ~~~