note 79746 added to function.tidy-get-root
| From: | james dot ellis at gmail dot com | Date: | Tue, 11 Dec 2007 10:11:04 +0000 |
| Subject: | note 79746 added to function.tidy-get-root | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133356@lists.php.net to get a copy of this message | ||
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>
*/
?>
----
Server IP: 203.202.10.60
Probable Submitter: 202.173.133.239
----
Manual Page -- http://www.php.net/manual/en/function.tidy-get-root.php
Edit -- https://master.php.net/note/edit/79746
Del: integrated -- https://master.php.net/note/delete/79746/integrated
Del: useless -- https://master.php.net/note/delete/79746/useless
Del: bad code -- https://master.php.net/note/delete/79746/bad+code
Del: spam -- https://master.php.net/note/delete/79746/spam
Del: non-english -- https://master.php.net/note/delete/79746/non-english
Del: in docs -- https://master.php.net/note/delete/79746/in+docs
Del: other reasons-- https://master.php.net/note/delete/79746
Reject -- https://master.php.net/note/reject/79746
Search -- https://master.php.net/manage/user-notes.php