(PHP 4 >= 4.3.0, PHP 5, PHP 7) exif_imagetype…
April 19, 2019
PHP: 正则提取文章中所有图片地址, get image src attribute (regular expression)
<?php // Source: http://goo.gl/qyLFbg $html = '<img border="0" src="/images/image.jpg" alt="Image" width="100" height="100" />'; preg_match( '@src="([^"]+)"@' , $html, $match ); $src = array_pop($match); // will return /images/image.jpg echo $src;
大段文章的话,使用:
<?php $content = '{lots of text and lots of images}'; preg_match_all('@img\s*src="([^"]+)"@',$content, $result); var_dump($result);
本文:PHP: 正则提取文章中所有图片地址, get image src attribute (regular expression)