note 79746 deleted from function.tidy-get-root by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 May 2009 12:58:55 +0000 |
| Subject: | note 79746 deleted from function.tidy-get-root by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154185@lists.php.net to get a copy of this message | ||
Note Submitter: james dot ellis at gmail dot com
----
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>
*/
?>