日期:2014-05-17 浏览次数:20435 次
$str = '请问怎么在一堆源码中匹配以下字符
img id="main-image" src="http://ecx.images-mazon.com/images/I/41Auzc7RBPL._SY300_.jpg"';
$p = '#img\s*id="main-image"\s*src="(http://ecx\.images-mazon\.com/images/I/.+\.(jpg
------解决方案--------------------
gif
------解决方案--------------------
jpeg
------解决方案--------------------
png))"#U';
preg_match($p, $str, $result) && var_dump($result);
$html = '<div><img id="main-image" src="http://ecx.images-mazon.com/images/I/41Auzc7RBPL._SY300_.jpg" /></div>';
$doc = new DOMDocument();
$doc->loadHTML($html);
echo $doc->getElementById('main-image')->getAttribute('src');
$str='img id="main-image" src="http://ecx.images-mazon.com/images/I/41Auzc7RBPL._SY300_.jpg"';
$p =
------解决方案--------------------
img id="main-image" src="(.*)"
------解决方案--------------------
iUs;
preg_match($p, $str, $result);
print_r($result);
//如果你只需要对获取到的网址里那个图片名称那么你需要分割
$ep=explode('/',$result[0]);
echo $ep[5];