我想知道PHP中获取HTML页面元素的img标签的src属性是怎么获取的?
比如这段代码----<p><imgborder="0"alt=""src="/joke/images/joke/2015-09-09_870/20150909103535...
比如这段代码----<p><img border="0" alt="" src="/joke/images/joke/2015-09-09_870/20150909103535486.jpg" width="260" height="293">我要如何获取src属性的值,有代码示范和注释的话就更棒了,谢谢大神
展开
2个回答
2015-11-05
展开全部
$img='<p><img border="0" alt="" src="/joke/images/joke/2015-09-09_870/20150909103535486.jpg" width="260" height="293">';
$result = preg_replace ( "/.*<img[^>]*src[=\s\"\']+([^\"\']*)[\"\'].*/", "$1", $img );
echo $result . "\n";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询