This article introduces an example of code that uses regular expressions to match image addresses in PHP. Friends in need can refer to it.
php regular match image address, the code is as follows: <?php //图片地址 正则匹配 //http://bbs.it-home.org function Getpics($body) { global $weburl; //$body = strtolower($body); $img_array = array(); preg_match_all("/(src|SRC)=[\"|'| ]{0,}((http|HTTP):\/\/(.*)\.(gif|jpg|GIF|JPG|png))/isU",$body,$img_array); $img_array = array_unique($img_array[2]); foreach($img_array as $key=>$value) { $url = $value; $fileurl = "/pic.php?s=".base64_encode($url); $body = str_replace($url,$fileurl,$body); } return $body; } ?> Copy after login |