PHP W3C Validation

This little PHP snippet shows you how to check if site is W3C valid. There is a cURL and file_get_contents() version, both of them are correct just pick one that suits your needs.
If you want to use it with AJAX, just replace return with echo, and then check with JavaScript. That's all there is to it


function w3c($url){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL, "http://validator.w3.org/check?uri=$url");
	$html = curl_exec($ch);
	curl_close($ch);
	if(strpos($html,"Passed")===false){return "0";}else{return "1";}
}


file_get_contents()


function w3c($url){
	$html = file_get_contents("http://validator.w3.org/check?uri=$url");
	if(strpos($html,"Passed")===false){return "0";}else{return "1";}
}
©2009-2011 Webarto • web design & development • Tuzla // Sarajevo // Beograd