PHP 用 tidy_parse_file() 函数提取 HTML 中的链接

2015-01-04 0 266
PHP 用 tidy_parse_file() 函数提取 HTML 中的链接
<?php
      function dump_urls(tidy_node $node, &$urls = NULL) {
            $urls = (is_array($urls)) ? $urls : array();

            if(isset($node->id)) {
                  if($node->id == TIDY_TAG_A) {
                        $urls[] = $node->attribute['href'];
                  }
            }

            if($node->hasChildren()) {
                  foreach($node->child as $child) {
                        dump_urls($child, $urls);
                  }
            }
                       return $urls;
      }

      $tidy = tidy_parse_file("http://www.php.net/");
      $urls = dump_urls($tidy->body());
      print_r($urls);
?>

遇见资源网 php PHP 用 tidy_parse_file() 函数提取 HTML 中的链接 http://www.ox520.com/7166.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务