Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Based HTML Validator

I need to find a PHP based HTML (as in WC3-Like) Validator that can look for invalid HTML or XHTML. I've searched Google a little, but was curious if anyone has used one they particularly liked.

I have the HTML in a string:

$html = "<html><head>.....</body></html>";

And I would like to be able to test the page, and have it return the errors. (Not echo/print anything)

I've seen:
-http://www.bermi.org/xhtml_validator
-http://twineproject.sourceforge.net/doc/phphtml.html

The background for this is that I'd like to have a function/class that I run on every page, check if the file has been modified since the last access date (or something similar to that), and if it hasn't, run the validator so I am immediately notified of invalid HTML while coding.

like image 536
Tyler Carter Avatar asked Sep 20 '25 22:09

Tyler Carter


2 Answers

There's no need to reinvent the wheel on this one. There's already a PEAR library that interfaces with the W3C HTML Validator API. They're willing to do the work for you, so why not let them? :)

like image 79
Robert Elwell Avatar answered Sep 22 '25 12:09

Robert Elwell


While it isn't strictly PHP, (it is a executable) one i really like is w3c's HTML tidy. it will show what is wrong with the HTML, and fix it if you want it to. It also beautifies HTML so it doesn't look like a mess. runs from the command line and is easy to integrate into php.

check it out. http://www.w3.org/People/Raggett/tidy/

like image 39
Byron Whitlock Avatar answered Sep 22 '25 12:09

Byron Whitlock