php tidy_parse_file() 函数提取 HTML 中的链接
tidy_parse_file() 函数提取 HTML 中的链接 [代码片段(28行)]
<?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("<a href="http://outofmemory.cn
$urls = dump_urls($tidy->body());
print_r($urls);
?>
//该片段来自于http://outofmemory.cn
精彩图集
精彩文章






