正则表达式获取源代码的图像URL

时间:2017-06-07 17:51:11

标签: php html regex image url

  • 我想用Js / HTML获取一些图像的URL: img class =" img-responsive" ID =" Q72D2600000-MDYI" SRC =" HTTPS:?//s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI $ $ 2014_G_xxlarge" ALT =" Q72D2600000-MDYI" />

  • 寻找能够检测图片网址的解决方案。所以输出将是: 的 https://s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI?$ $ 2014_G_xxlarge

1 个答案:

答案 0 :(得分:0)

以下代码可能有帮助

$html = '<img class="img-responsive" id="Q72D2600000-MDYI" src="https://s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI?$2014_G_xxlarge$" alt="Q72D2600000-MDYI" />';
preg_match('/<img\s.*?\bsrc="(.*?)".*?>/si', $html, $matches);

$image_src = $matches[1];

echo $image_src;

输出

https://s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI?$2014_G_xxlarge$