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}';
pr… Read More