提取特定<a href=""> URLs out of the document</a>

时间:2010-07-20 07:37:13

标签: php string url extract preg-match

我认为这应该是基本的,但我仍然无法理解它。 假设有相当数量的HTML文档,我需要从中捕获每个图像URL。

内容的其余部分会更改,但网址的基础始终相同,例如:http://images.examplesite.com/images/

所以我想提取包含该部分的每个字符串。问题是它们总是与<a href=''><img src=''>标签混在一起,所以我怎么能把它们删掉? preg_match可能?

2 个答案:

答案 0 :(得分:1)

尝试类似:preg_match_all('/http:\/\/images\.examplesite\.com\/images\/(.*?)"/i', $html_data, $results, PREG_SET_ORDER)

答案 1 :(得分:0)

您可以使用html dom parser

或使用正则表达式。

  preg_match_all("/http:\/\/images.examplesite.com\/images\/(.*?)\"/s", $str, $preg);
  print_r($preg);
相关问题