Heim >Backend-Entwicklung >PHP-Tutorial >PHP 用 tidy_parse_file() 函数提取 HTML 中的链接

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:11:281040Durchsuche
  1. function dump_urls(tidy_node $node, &$urls = NULL) {
  2. $urls = (is_array($urls)) ? $urls : array();
  3. if(isset($node->id)) {
  4. if($node->id == TIDY_TAG_A) {
  5. $urls[] = $node->attribute['href'];
  6. }
  7. }
  8. if($node->hasChildren()) {
  9. foreach($node->child as $child) {
  10. dump_urls($child, $urls);
  11. }
  12. }
  13. return $urls;
  14. }
  15. $tidy = tidy_parse_file("http://www.php.net/");
  16. $urls = dump_urls($tidy->body());
  17. print_r($urls);
  18. ?>
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn