0

I think this should be elementary, but I still can't get my head around it. Let's say there's fair amount of HTML documents and I need to catch every image URLs out of them.

The rest of the content changes, but the base of the url is always the same for example: http://images.examplesite.com/images/,

So I want to extract every string that contains that part. the problem is that they're always mixed with <a href=''> or <img src=''> tags, so how could I drop them out? preg_match probably?

David
  • 208,112
  • 36
  • 198
  • 279
Seerumi
  • 1,937
  • 3
  • 18
  • 16
  • possible duplicate of [PHP Xpath : get all href values that contain needle](http://stackoverflow.com/questions/2392393/php-xpath-get-all-href-values-that-contain-needle) – Gordon Jul 20 '10 at 07:42
  • 1
    You can also use DOM as shown in [Preg_Match All A href](http://stackoverflow.com/questions/1519696/preg-match-all-a-href/1519791#1519791). Just change the XPath to the one given in the linked duplicate. – Gordon Jul 20 '10 at 07:48

2 Answers2

1

Try something like: preg_match_all('/http:\/\/images\.examplesite\.com\/images\/(.*?)"/i', $html_data, $results, PREG_SET_ORDER)

Narcis Radu
  • 2,519
  • 22
  • 33
  • wow, that was fast. it leaves one " after the string, but believe it or not I got rid of it myself ;D thanks again! – Seerumi Jul 20 '10 at 07:57
0

You can either use html dom parser

or use regular expression.

  preg_match_all("/http:\/\/images.examplesite.com\/images\/(.*?)\"/s", $str, $preg);
  print_r($preg);
ahmetunal
  • 3,930
  • 1
  • 23
  • 26