PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

tidy_get_status> <tidy_get_release
Last updated: Fri, 03 Oct 2008

view this page in

tidy_get_root

(PHP 5, PECL tidy:0.5.2-1.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

<?php

$html 
= <<< HTML
  <html><body>

    <p>paragraphe</p>
    <br/>

   </body></html>
  HTML;

  $tidy = tidy_parse_string($html);
  dump_nodes($tidy
->root(), 1);


  function dump_nodes($node, $indent) {

    if($node
->hasChildren()) {
      foreach($node
->child as $child) {
        echo str_repeat('.', $indent*2) . ($child
->name ? $child->name : '"'.$child->value.'"'). "\n";

        dump_nodes($child, $indent+1);
      }
    }

  }
?>

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.



add a note add a note User Contributed Notes
tidy_get_root
james dot ellis at gmail dot com
11-Dec-2007 11:11
To avoid temporary insanity, it's worth noting that if you are pushing HTML through tidy with the show-body-only option set to TRUE, then calling tidy->root() will return the HTML including doctype, html, head, title tags etc.
To get your body only HTML, do the usual thing of casting the tidy object as a string.

<?php
//assume $config and $encoding are set for this example
$markup = "<h2>Welc<foo>ome</h2>";
$tidy = new Tidy;
$tidy->parseString($markup, $config, $encoding);
$tidy->cleanRepair();
print (string)
$tidy->root();
/**
result:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<h2>Welcome</h2>
</body>
</html>
*/
print (string)$tidy;
/**
result:
<h2>Welcome</h2>
*/
?>

tidy_get_status> <tidy_get_release
Last updated: Fri, 03 Oct 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites