An example of code to match image address in php

WBOY
Release: 2016-07-25 08:58:06
Original
1159 people have browsed it
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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template