$html = "<img src='http://www.csdn.net/images/homeimage/top_1.gif' width='20' height='25'>";
preg_match('/http:\/\/(.*?)\.gif/', $html, $match);
echo $match[0];//不是很好,但应该可以用吧!
preg_match('/http:\/\/(.*?)\.gif/', $html, $match);
echo $match[0];//不是很好,但应该可以用吧!
http://www.csdn.net/images/homeimage/top_1.gif 是一个路径啊
如果你想用ASP语句将这个路径显示出来
那你可以把这个路径保存到数据库中啊
通过rs("X")就可以在网页中显示数据库中的内容 其中X是数据库中的字段名
只取 在 <img 里面的下面是被取的内容:
---------------
<img src="http://www.csdn.net/images/homeimage/top_1.gif" width="20" height="25">
http://www.csdn.net/images/homeimage/top_1.gif
http://www.csdn.net/images/homeimage/top_2.gif
----------------------------
需要只取 <img src="http://www.csdn.net/images/homeimage/top_1.gif" width="20" height="25"> 里面的 http://www.csdn.net/images/homeimage/top_1.gif
preg_match_all($re, $html, $match);
print_r($match[1]);
$str.= "<img src='http://www.csdn.net/images/homeimage/top_2.gif' width='20' height='25'>";
$str.="<img src='http://www.csdn.net/images/homeimage/top_1.gif' width=20 >";
preg_match_all('/<img\s+src=[\"\'](.*)[\"\'].*>/iU',$str,$getstr);
print_r($getstr[1]);
$re = "/<img\s+src=(\"|\')(.+)(\\1)/isU";
preg_match_all($re, $html, $match);
print_r($match[2]);
$str = <<< HTML
<img src="http://www.csdn.net/images/homeimage/top_1.gif" width="20" height="25">
<img src='http://www.csdn.net/images/homeimage/top_1.gif' width='20' height='25'>
<img src=http://www.csdn.net/images/homeimage/top_1.gif width=20 >
HTML;preg_match_all("/<img\s.*src=([\"']?)(.+)\\1[\s>]/iU",$str,$regs);
print_r($regs[2]);
?>
这样写的理由如下:
1、当标签有id或事件响应属性时,通常写作
<img id="id" onclick="function()" src="url" ...>
尤其是“在线编辑器”会按属性名的字母顺序排列属性
2、url可以用“""”、“''”括起,也可以没有
3、一个url应被同样的定界符括起
4、<img\s.*src= 更复杂的写法是 <img\s?.*\ssrc=
似乎并无必要,要确保是src单词可用 <img\s.*\bsrc=