I want to get some URLs of images in Js/HTML: img class="img-responsive" id="Q72D2600000-MDYI" src="https://s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI?$2014_G_xxlarge$" alt="Q72D2600000-MDYI" />
Looking for solution that will detect image url. So the output will be: https://s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI?$2014_G_xxlarge$
Asked
Active
Viewed 303 times
0

Rong Rêu
- 21
- 1
-
Parse the HTML and pull the `src` attribute. – chris85 Jun 07 '17 at 18:04
-
2Possible duplicate of [Regex & PHP - isolate src attribute from img tag](https://stackoverflow.com/questions/2120779/regex-php-isolate-src-attribute-from-img-tag) – Adrian Ghiuta Jun 07 '17 at 18:17
1 Answers
0
The below code may be helpfull
$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;
Output
https://s7d5.scene7.com/is/image/Guess/Q72D2600000-MDYI?$2014_G_xxlarge$

Ravinder Reddy
- 3,869
- 1
- 13
- 22
-
Thank you very much. I am using a Scrapebox 2.0 tool. I need one that regex to get the image URL from that source code. Is there a solution for me? Simply a reasonable regex code – Rong Rêu Jun 07 '17 at 18:43