Home >Backend Development >PHP Tutorial >PHP extracts the image address in the string [regular expression]_PHP tutorial

PHP extracts the image address in the string [regular expression]_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:23:061009browse

Copy code The code is as follows:

$str='

';
$pattern="/<[img|IMG].*?src=[ '|"](.*?(?:[.gif|.jpg]))['|"].*?[/]?>/";
preg_match_all($pattern,$str,$match );
print_r($match);
?>

The result shows:
Array
(
[0] => Array
(
[0] =>
)

[1 ] => Array
(
[0] => upfiles/2009/07/1246430143_1.jpg
)
)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324555.htmlTechArticleCopy the code as follows: ?php $str='pimg border="0" src="upfiles/2009/ 07/1246430143_1.jpg" alt=""//p'; $pattern="/[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg]) )['|"].*?[/]?/";...
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