2010-07-20 2 views
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.Extraction spécifique <a href> URLs out of the document

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?

+0

double possible de [PHP Xpath: obtenir toutes les valeurs qui contiennent href aiguille] (http://stackoverflow.com/questions/2392393/php-xpath-get-all-href-values-that-contain- aiguille) – Gordon

+1

Vous pouvez également utiliser DOM comme indiqué dans [Preg_Match All A href] (http://stackoverflow.com/questions/1519696/preg-match-all-a-href/1519791#1519791). Il suffit de changer le XPath à celui donné dans le doublon lié. – Gordon

+0

Je vais l'essayer :) – Seerumi

Répondre

1

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

+0

wow, c'était rapide. il en laisse un après la ficelle, mais croyez-le ou non, je m'en suis débarrassé moi-même, merci encore! – Seerumi

0

You can either use html dom parser

ou d'utiliser une expression régulière.

preg_match_all("/http:\/\/images.examplesite.com\/images\/(.*?)\"/s", $str, $preg); 
    print_r($preg); 
Questions connexes