PHP Function: W3C Validation
A cURL enabled function that passes a URL through W3C's (X)HTML, CSS, and RSS feed validation tools and simply returns whether the URL is valid or contains errors. This script is essentially the cURL multi socket example script by Esrun with a few minor additions. See below for the original (much slower function) I was using before.
<?php function w3c_validation($domain) {
// Begin code by Esrun at http://www.onlinehoster.com
$urls = array("http://validator.w3.org/check?uri={$domain}","http://jigsaw.w3.org/css-validator/validator?uri={$domain}", "http://validator.w3.org/feed/check.cgi?url={$domain}");
$socketh = curl_multi_init();
foreach($urls as $i => $url){
$socket[$i] = curl_init($url);
curl_setopt($socket[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($socket[$i], CURLOPT_FOLLOWLOCATION, 1);
curl_multi_add_handle($socketh, $socket[$i]);
}
do { $x = curl_multi_exec($socketh, $working); } while ($working);
foreach($urls as $i => $url){
$data[] = curl_multi_getcontent($socket[$i]);
curl_close($socket[$i]);
}
// End code by Esrun
if(preg_match('%Congratulations%',$data[0])) { echo "Valid Markup | "; } else { echo "Invalid Markup! | "; }
if(preg_match('%Congratulations! No Error Found.%',$data[1])) { echo "Valid CSS | "; } else { echo "Invalid CSS! | "; }
if(preg_match('%Congratulations!%',$data[2])) { echo "Valid RSS"; } else { echo "Invalid RSS!"; }
} ?>
Alternatively or if you do not have cURL enabled on your server you can use the following script to achieve the exact same output (just with much slower results).
<?php function w3c_validation($domain) {
$dataMarkup = file_get_contents("http://validator.w3.org/check?uri={$domain}");
$dataCss = file_get_contents("http://jigsaw.w3.org/css-validator/validator?uri={$domain}");
$dataRss = file_get_contents("http://validator.w3.org/feed/check.cgi?url={$domain}");
//-output
if(preg_match('%Congratulations%',$dataMarkup)) { echo "Valid Markup | "; } else { echo "Errors Found in Markup! | "; }
if(preg_match('%Congratulations! No Error Found.%',$dataCss)) { echo "Valid CSS | "; } else { echo "Errors Found in CSS! | "; }
if(preg_match('%Congratulations!%',$dataRss)) { echo "Valid RSS"; } else { echo "Errors Found in RSS!"; }
} ?>






