Cameron's Thoughts
Archives
Programming

Validating Web Pages

Thought I would share this bit of code as some people might find it useful. Ever since I started working to make sure my pages were compatible, I have come up with a number of things to help me to accomplish this. Now, every page on this site should be fully xHTML compliant and I have setup a number of backend protections to stop most things from causing the sites to stop validating. One thing I wrote was a simple PHP function that can be used in any script that gives some feedback as to if a website is valid or not.




function validate_page($url)

{

$url = urlencode($url);

$site = "http://validator.w3.org/check?uri=$url";

$data = implode("", file($site));

$result = preg_match_all ("/\<h2 class\=\"valid\"\>/", $data, $matches);

return $result;

}


Usage:


$page = "http://www.cbulock.com/";

$result = validate_page($page);


Basically, give the function a URL, it will send back either a 1 or 0 depending on if it's a valid page or not. If this is something useful, go ahead and use it, it's free to use as you please.