求php中正则表达式从html代码中获取图片路径

来源:百度知道 编辑:UC知道 时间:2024/07/05 02:33:20
形如:
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/Tree.jpg" /></p>
的html代码,怎样用preg_match_all来获取src地址(就是引号里面那串),正则怎么表示?谢谢~~!!!!!!!!!!!

<?php
$test = '<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/Tree.jpg" /></p>
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/sf/Tree.jpg" /></p>
fsdafasdfasdfasdf
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/elm.jpg" /></p>

sdfasdfasdf<p>
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/28/maple.jpg" /></p>

sdf32414撒旦发是否
<p>444<img height="768" width="1024" alt="" src="/uploadfiles/40/Tree.jpg" /></p>';

preg_match_all("/<p>.*src=\"([^^]*?)\".*<\/p>/i",$test,$match);
print_r($match[1])