PHP 用 tidy_parse_file() 函数提取 HTML 中的链接
PHP 用 tidy_parse_file() 函数提取 HTML 中的链接 **php代码**```{.php}lt;?php function dump_urls(tidy_node $node, amp;$urls = NULL) { $urls = (is_array($urls)) ? $urls : array(); if(isset($node-gt;id)) {
php代码
<?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 的 md5 和 uniqid 函数使用示例
- 下一篇:php记录页面执行时间
精彩图集
精彩文章