Home  >  Article  >  Backend Development  >  An example of code to match image address in php

An example of code to match image address in php

WBOY
WBOYOriginal
2016-07-25 08:58:061120browse
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;
}
?>


Statement:
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