Manuel PHP

tidy_get_root

(PHP 5, PECL tidy 0.5.2-1.0.0)

tidy_get_root Retourne un objet tidyNode représentant la racine du document HTML

Description

Style procédural :

tidyNode tidy_get_root ( tidy $object )

Style orienté objet :

tidyNode tidy->root ( void )

tidy_get_root() retourne un objet tidyNode représentant la racine de l'arbre Tidy analysé.

Exemple #1 Affichage des noeuds

  1. <?php
  2.  
  3. $html = <<< HTML
  4. <html><body>
  5.  
  6.    <p>paragraphe</p>
  7.    <br/>
  8.  
  9. </body></html>
  10. HTML;
  11.  
  12. $tidy= tidy_parse_string($html);
  13. dump_nodes($tidy->root(), 1);
  14.  
  15.  
  16. function dump_nodes($node,$indent) {
  17.  
  18.    if($node->hasChildren()) {
  19.     foreach($node->childas$child) {
  20.       echo str_repeat('.',$indent*2) . ($child->name?$child->name: '"'.$child->value.'"'). "\n";
  21.  
  22.       dump_nodes($child,$indent+1);
  23.     }
  24.    }
  25.  
  26. }
  27. ?> 

L'exemple ci-dessus va afficher :

..html ....head ......title ....body ......p ........"paragraphe" ......br

Note: Cette fonction n'est disponible qu'avec le Zend Engine 2, c'est à dire PHP >= 5.0.0.


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique