0

i have checked many answers but i am still straggling to find a solution.

Case 1:

<div id="vsImage" itemprop="image" data-zoom-src="http://example.com/product/760x1013/V373872.jpg"/>

Case 2:

<a href="#"><img src="http://example.com/product/760x1013/V373872.jpg"></a>

I know i can easily extract all images from tag with PHP DOMDocument, but in this case 1 image source is not in tag.

Maybe the question is, can i somehow get all *.jpg strings from html?

Thanks in advance.

1
  • You can search for .jpg and then seach your way back (index) to the last =. Commented Aug 25, 2013 at 18:58

2 Answers 2

4

Try this:

$content = "your HTML content $here";
$matches = NULL;
$pattern = '/(?:http|https|ftp):\/\/\S+\.(?:jpg|jpeg)/';
preg_match_all ($pattern, $content, $matches);
Sign up to request clarification or add additional context in comments.

2 Comments

It catches only case #2 ;)
And also is it possible to adapt this regex to match *.jpg string with relative path. (not starting with http...)?
0

Match all strings between http and .jpg that doesn't contain a ".

/http[^\"]+\.jpg/g

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.