2010-07-20 4 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.특정 추출 <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

가능한 중복 [PHP XPath는 : 바늘을 포함하는 모든 HREF 값을 가져] (http://stackoverflow.com/questions/2392393/php-xpath-get-all-href-values-that-contain- 바늘) – Gordon

+1

또한 [Preg_Match 모두 A href] (http://stackoverflow.com/questions/1519696/preg-match-all-a-href/1519791#1519791)와 같이 DOM을 사용할 수 있습니다. XPath를 링크 된 복제물에 지정된 XPath로 변경하면됩니다. – Gordon

+0

나는 그것에게 시도를 줄 것이다 :) – Seerumi

답변

1

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

+0

와우, 그것은 빨랐다. 그것은 하나의 문자열을 남긴다. 그러나 그것을 믿을 지 안할까? 나는 그것을 스스로 없애 버린다. D 다시 한번 감사한다. – Seerumi

0

You can either use html dom parser

또는 정규 표현식을 사용하십시오.

preg_match_all("/http:\/\/images.examplesite.com\/images\/(.*?)\"/s", $str, $preg); 
    print_r($preg); 
관련 문제