The HTML Validation class uses Tidy (which requires libtidy from: http://tidy.sourceforge.net) to validate HTML code snippets. The snippet can be passed to the construct, or seperatly through the validate() function (which returns the results). Use setConfig() to set Tidy configuration options (listed at: http://tidy.sourceforge.net/docs/quickref.html).
<php
// Include this file.
include('html_validation.class.php');
// Store some invalid HTML in $string
$string="<b>TEST<b>";
// Instantiate the class, passing the bad HTML to the construct.
$validation = new htmlValidation($string);
// echo out the status of the class, including the errors stored in $validation->errors
echo $validation->displayStatus();
This will output:
--- DOCUMENT STATUS ---
DTD:XHTML 1.0 Transitional
CONFIG SETTINGS:
input-encoding : UTF8
VALIDATION ERRORS:
line 1 column 259 - Warning: <b> is probably intended as </b>
// We might also use $validation-errors for flow control:
if($validation->errors){
echo $validation->errors;
}else{
echo "The snippet is valid";
}
| Version | Release Date | Release Notes | Download |
|---|---|---|---|
| 1.0 | December 6, 2007 | This is the first release of this class, so it is bound to be buggy. If you find any bugs or have any suggestions for improvements, please feel free to contact me at Nick@LaPrell.org. |