X / Html Validator in PHP

First: I know that there is an interface for the W3C validator: http://pear.php.net/package/Services_W3C_HTMLValidator/ But I do not know if I can install it on a cheap hosting server. I do not think so.

I need a validator for my seo tools in my content management system, so it should be pretty portable.

I would like to use W3C, but only if it is portable. I can also use Curl for this, but it will not be an elegant solution.

The best I've found so far: http://phosphorusandlime.blogspot.com/2007/09/php-html-validator-class.html

Is there any validator comparable to W3C but portable (only PHP, which is not dependent on user packages)?

+8
html php validation xhtml w3c-validation
source share
2 answers

If you want to check (X) HTML documents, you can use the built-in PHP DOM extension:

Example from the manual:

 $dom = new DOMDocument; $dom->load('book.xml'); // see docs for load, loadXml, loadHtml and loadHtmlFile if ($dom->validate()) { echo "This document is valid!\n"; } 

If you need individual errors, select them libxml_get_errors()

+9
source share

I asked a similar question , and you can check out some of them there.

In general, I would recommend either running the HTML code on a neat host, or writing a short script to test through W3C remotely. Personally, I don't like the neat option, because it reformatts your code, and I hate how it puts <p> tags on every line.

Here is a link to tidy and here is a link to various W3C verification tools .

Keep in mind that HTML validation does not work with server-side code; It only works after evaluating your PHP. This means that you will need to run your code through the host PHP interpreter, and then "connect" it to either the tidy utility or the remote verification service. This command will look something like this:

$ php myscript.php | tidy #options go here

Personally, I ultimately decided to give up the headache and simply visualize the page, copy the source and verify it using direct input in the W3C verification utility. There are so many times that you still need to check the page, and there was more to automating it than it was worth.

Good luck.

+1
source share

All Articles