note 52139 added to function.dom-domdocument-savehtml
| From: | tyson at clugg dot net | Date: | Fri, 22 Apr 2005 00:44:56 +0000 |
| Subject: | note 52139 added to function.dom-domdocument-savehtml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88379@lists.php.net to get a copy of this message | ||
<?php
// Using DOM to fix sloppy HTML.
// An example by Tyson Clugg <tyson@clugg.net>
//
// vim: syntax=php expandtab tabstop=2
function tidyHTML($buffer)
{
// load our document into a DOM object
$dom = @DOMDocument::loadHTML($buffer);
// we want nice output
$dom->formatOutput = true;
return($dom->saveHTML());
}
// start output buffering, using our nice
// callback funtion to format the output.
ob_start("tidyHTML");
?>
<html>
<p>It's like comparing apples to oranges.
</html>
<?php
// this will be called implicitly, but we'll
// call it manually to illustrate the point.
ob_end_flush();
?>
The above code takes out sloppy HTML:
<html>
<p>It's like comparing apples to oranges.
</html>
And cleans it up to the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>It's like comparing apples to oranges.
</p></body></html>
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-savehtml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52139
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52139&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52139&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52139&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52139&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52139&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52139&report=yes
Search -- http://master.php.net/manage/user-notes.php