当前位置:Gxlcms >
PHP教程 >
PHP用tidy_parse_file()函数提取HTML中的链接
PHP用tidy_parse_file()函数提取HTML中的链接
时间:2021-07-01 10:21:17
帮助过:18人阅读
<无详细内容>
- 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.com/");
- $urls = dump_urls($tidy->body());
- print_r($urls);
- ?>
|