时间:2021-07-01 10:21:17 帮助过:29人阅读
$str = '请问怎么在一堆源码中匹配以下字符
img id="main-image" src="https://img.gxlcms.com//Uploads-s/new/2019-09-21-201921/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 = '';
$doc = new DOMDocument();
$doc->loadHTML($html);
echo $doc->getElementById('main-image')->getAttribute('src');
$str='img id="main-image" src="https://img.gxlcms.com//Uploads-s/new/2019-09-21-201921/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];