Tidy up your html with php
By using the Tidy php class, you can format your html output.
Below is an example.
<?php
$html = "<html><head><title>a title</title></head><body>here is the body</body></html>";
$config = array('indent'=>true, 'output-xml'=>true, 'input-xml'=>true, 'wrap'=>'1000', 'indent-spaces'=>'8');
$tidy = new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
$html = tidy_get_output($tidy);
print($html);
?>
$html = "<html><head><title>a title</title></head><body>here is the body</body></html>";
$config = array('indent'=>true, 'output-xml'=>true, 'input-xml'=>true, 'wrap'=>'1000', 'indent-spaces'=>'8');
$tidy = new tidy();
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
$html = tidy_get_output($tidy);
print($html);
?>
The output will be nicely formatted and indented. Indented to 8 spaces.
References
- http://devzone.zend.com/article/761 »
- http://www.php.net/tidy »
- http://us2.php.net/manual/en/tidy.examples.basic.php »
[Click to add or edit comments])
Please prepend comments below including a date