tidy_get_status> <tidy_get_release
Last updated: Mon, 28 Dec 2009

tidy_get_root

(PHP 5, PECL tidy 0.5.2-1.0.0)

tidy_get_rootRetorna um objeto tidyNode representando a raiz da árvore analisada do tidy

Descrição

Modo procedural:

tidyNode tidy_get_root ( tidy $object )

Modo orientado a objeto:

tidyNode tidy->root ( void )

Retorna um objeto tidyNode representando a raiz da árvore analisada do tidy.

Exemplo #1 exibindo nodes

<?php

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

<p>paragraph</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);
        }
    }
}
?>

O exemplo acima irá imprimir:

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

Nota: Esta função somente está disponível com a Zend Engine 2 (PHP >= 5.0.0).



User Contributed Notes
tidy_get_root
james dot ellis at gmail dot com
11-Dec-2007 08: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: Mon, 28 Dec 2009