W3C local validation php class?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

W3C local validation php class?

Post by jaoudestudios »

Is there a way I can use php to validate with w3c my generated pages?

So I could run all the pages (views) on my website and show a table of results of each page and if they passed w3c validation?
i.e
page | url | w3c
----------------
home | http://localhost/index | pass
about | http://localhost/about/ | pass
contact | http://localhost/contact | fail

Another reason for this, is that I could then build additional columns for PHPUnit & Selenium. Just for a quick overview if any other developers or myself have broken something it can be sorted immediately.

Cheers
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: W3C local validation php class?

Post by Chris Corbyn »

I'm reasonably sure Tidy can do validation. Let me check.

All it requires is a SGML parser that interprets the rules in the DTD.

EDIT | I can't seem to find anything about validation using Tidy.

You can always POST the HTML to the W3C validator. This is basically what Firebug does when you use "Validate Local HTML".
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: W3C local validation php class?

Post by Eran »

The w3c validation service has an API - http://validator.w3.org/docs/api.html
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: W3C local validation php class?

Post by jaoudestudios »

Chris Corbyn wrote:You can always POST the HTML to the W3C validator. This is basically what Firebug does when you use "Validate Local HTML".
Sounds good.

Do i have to use AJAX or can I do it will plain PHP?

I will look at the api.

Cheers All
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: W3C local validation php class?

Post by Eran »

If you're using the API, it's a RESTful service. create an HTTP request using something like

Code: Select all

$result = file_get_contents('http://validator.w3.org/check' . $parameters);
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: W3C local validation php class?

Post by alex.barylski »

I think you can download the source and run the validator locally:

http://validator.w3.org/source/
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: W3C local validation php class?

Post by jaoudestudios »

Cool thanks, I will give it a try.

I have been having some issues with the http request. I keep getting connection closed.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: W3C local validation php class?

Post by JAB Creations »

It's simply best to use cURL. When you use the editor on my site to import CSS it actually validates it by creating a temporary file on the server, using cURL to validate (and then scan the resulting page for valid or invalid) and in the process completely offloads the entire validation process to the W3C server. Since they update the validator every so often you'll always be using the latest validation algorithms, doesn't get any better then that. The only possible downside is if the XHTML code on the validation page changes and breaks cURL's ability to figure out if the page is valid or not...but it's a small price to pay considering the trade-off's.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: W3C local validation php class?

Post by Eran »

It's definitely not simply best to use cURL, as it's way more complicated than a simple file_get_contents call. The reason it might be failing for you is that you might have safe mode in the PHP settings.
Also, the API is a webservice, it won't give a different response format when the validator is updated..
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: W3C local validation php class?

Post by alex.barylski »

It's definitely not simply best to use cURL, as it's way more complicated than a simple file_get_contents call.
1+
The reason it might be failing for you is that you might have safe mode in the PHP settings.
In addition to that I would look into the php.ini setting:

Code: Select all

allow_url_fopen = Off
Very common, I think it's the default for debian or ubuntu? Can't remember but check that setting anyways.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: W3C local validation php class?

Post by jaoudestudios »

Thanks guys.

Safe mode is definitely off. But not sure about allow_url_fopen, I will check now. Nope thats not it, it is set to on :(

w3c allow developers to install a validation server locally, is it worth giving that a go? http://validator.w3.org/docs/devel.html
Post Reply