PHP5 DOM/Tidy
Posted: Sun Apr 24, 2005 1:24 pm
Hello,
I was playing with the new features of PHP5 (the Tidy support and the DOM support).
I wrote the following code:
It opens a file (test2.html), checks all the table tags, and sets the border value to 0. So far so good, the problem arises with saving the DOM generated output to a file. The DOM functions only supports output to XML or HTML, not XHTML. In order to have valid XHTML markup, I had to use the Tidy functions to 'fix' the test.html file I just saved... then save that file again. Seems like a lot of work...
Does anyone have a better solution? or ideas?
p3x
I was playing with the new features of PHP5 (the Tidy support and the DOM support).
I wrote the following code:
Code: Select all
<?php
$dom = new domdocument;
$dom->load("test2.html");
$dom->formatOutput = TRUE;
$params = $dom->getElementsByTagName('table');
foreach ($params as $param) {
if ($param -> getAttribute('border')) {
$param -> setAttribute('border', 0);
}
}
$dom->saveHTMLFile('test.html');
$options = array("output-xhtml" => true, "clean" => true, "indent" => true, "indent-spaces" => 4, "wrap" => 100);
$tidy = tidy_parse_file("test.html", $options);
tidy_clean_repair($tidy);
$fp = fopen('test.html', 'w');
fwrite($fp, $tidy);
fclose($fp);
?>Does anyone have a better solution? or ideas?
p3x