I'm pretty sure this is not sending the correct request to the W3C (X)HTML validator. However I'm not experienced with cURL so maybe someone could help point me in the right direction please?
This script is merely checking the title element to determine if the URL submitted is valid. That's all I really need it to do! Suggestions please?
PHP Code:<?php
function check_html_compliance($url) {
$query_string = '';
foreach($_GET as $key => $val)
$query_string .= '&' . $key . '=' . $val;
if($query_string != '') {
$query_string = substr($query_string,1);
$referer = $url . '?' . $query_string;
} else
$referer = $url;
$ch = curl_init('http://validator.w3.org/check?verbose=1&uri='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_TIMEOUT,30);
$output = curl_exec($ch);
curl_close($ch);
var_dump $ch;
if (eregi('Validation Results',$output)) {
$start = strpos($output,"<title>") + 9;
$end = strpos($output,'</title>') - $start;
$retval = html_entity_decode(substr($output,$start,$end));
return 'no page sent?';
} else if (eregi('[Invalid]',$output)) {
$start = strpos($output,"<title>") + 9;
$end = strpos($output,'</title>') - $start;
$retval = html_entity_decode(substr($output,$start,$end));
return 'valid';
} else if (eregi('[Valid]',$output)) {
$start = strpos($output,"<title>") + 9;
$end = strpos($output,'</title>') - $start;
$retval = html_entity_decode(substr($output,$start,$end));
return 'invalid';
} else {
return 'unknown error';
}
}
echo check_html_compliance($_POST['url']);
?>
<form>
<input name="url" type="text" value="http://www.google.com/" />
<input type="submit" value="Validate URL" />
</form>




Reply With Quote
Bookmarks