note 105352 added to tidy.examples.basic
| From: | matthewkastor at gmail dot com | Date: | Thu, 11 Aug 2011 02:00:45 +0000 |
| Subject: | note 105352 added to tidy.examples.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182416@lists.php.net to get a copy of this message | ||
This function takes a string of HTML and runs it through HTML Tidy. It outputs a string of XHTML.
This is intended for processing entire pages by default. You can supply an array to the second
parameter of this function and it will override the default settings. Of course just changing the
array inside the function will change the default settings. :D
There is a cheat sheet for the HTML Tidy options located here: http://tidy.sourceforge.net/docs/quickref.html
There are a few I didn't put in the default array. ;) only a few.
example use of this function:
<?php
$fileAsString = file_get_contents( 'path/to/file.html' );
$cleanOutput = cleaning( $fileAsString );
echo $cleanOutput;
?>
And here it is. I hope it helps you.
<?php
// Tested on PHP 5.3.5
/* $what_to_clean is a string, $tidy_config is an array of options. $tidy_config is optional. */
function cleaning($what_to_clean, $tidy_config='' ) {
$config = array(
'show-body-only' => false,
'clean' => true,
'char-encoding' => 'utf8',
'add-xml-decl' => true,
'add-xml-space' => true,
'output-html' => false,
'output-xml' => false,
'output-xhtml' => true,
'numeric-entities' => false,
'ascii-chars' => false,
'doctype' => 'strict',
'bare' => true,
'fix-uri' => true,
'indent' => true,
'indent-spaces' => 4,
'tab-size' => 4,
'wrap-attributes' => true,
'wrap' => 0,
'indent-attributes' => true,
'join-classes' => false,
'join-styles' => false,
'enclose-block-text' => true,
'fix-bad-comments' => true,
'fix-backslash' => true,
'replace-color' => false,
'wrap-asp' => false,
'wrap-jste' => false,
'wrap-php' => false,
'write-back' => true,
'drop-proprietary-attributes' => false,
'hide-comments' => false,
'hide-endtags' => false,
'literal-attributes' => false,
'drop-empty-paras' => true,
'enclose-text' => true,
'quote-ampersand' => true,
'quote-marks' => false,
'quote-nbsp' => true,
'vertical-space' => true,
'wrap-script-literals' => false,
'tidy-mark' => true,
'merge-divs' => false,
'repeated-attributes' => 'keep-last',
'break-before-br' => true,
);
if( $tidy_config == '' ) {
$tidy_config = &$config;
}
$tidy = new tidy();
$out = $tidy->repairString($what_to_clean, $tidy_config, 'UTF8');
unset($tidy);
unset($tidy_config);
return($out);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 68.41.94.241
----
Manual Page -- http://www.php.net/manual/en/tidy.examples.basic.php
Edit -- https://master.php.net/note/edit/105352
Del: integrated -- https://master.php.net/note/delete/105352/integrated
Del: useless -- https://master.php.net/note/delete/105352/useless
Del: bad code -- https://master.php.net/note/delete/105352/bad+code
Del: spam -- https://master.php.net/note/delete/105352/spam
Del: non-english -- https://master.php.net/note/delete/105352/non-english
Del: in docs -- https://master.php.net/note/delete/105352/in+docs
Del: other reasons-- https://master.php.net/note/delete/105352
Reject -- https://master.php.net/note/reject/105352
Search -- https://master.php.net/manage/user-notes.php