Re: Generating a SOAP request in PHP to W3C Validator?
Posted: Fri Jun 06, 2008 9:26 pm
Speed Comparison
preg_match
stristr
preg_match
Code: Select all
<?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?uri=referer');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
curl_close($ch);
if (preg_match("/This page is valid/i", $output)) {
$retval = '<b style="color: #0f0;">Valid!</b>';
}
else {$retval = '<b style="color: #f00;">Invalid!</b>';}
return $retval;
//return 'result1 = '.$result1.', and result2 = '.$result2.', and result3 = '.$result3;
} //end check_html_compliance
if (isset($_GET['url'])) {echo 'The (X)HTML at the domain '.$_GET['url'].' is '.check_html_compliance($_GET['url']);}
else {echo '<b style="color: #00f;">Choose a domain name to validate please.</b>';}
echo "<br />\n";
$time_start = microtime(true);
// Sleep for a while
usleep(1000);
$time_end = microtime(true);
$time = $time_end - $time_start;
//echo "Rendered in $time seconds\n";
echo 'Rendered in ';
//echo substr($time, 0, 7);
echo round($time, 7);
echo ' seconds using <b style="color: #00f;">preg_match</b>.';
?>
<form method="get">
<select name="url">
<option value="http://www.google.com/">googlecom</option>
<option selected="selected" value="http://www.jabcreations.com/">jabcreations.com</option>
</select>
<input type="submit" value="Validate URL" />
</form>Code: Select all
<?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?uri=referer');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
curl_close($ch);
if (stristr($output, 'This Page Is Valid') == TRUE)
{
$retval = '<b style="color: #0f0;">Valid!</b>';
}
else {$retval = '<b style="color: #f00;">Invalid!</b>';}
return $retval;
}
if (isset($_GET['url'])) {echo 'The (X)HTML at the domain '.$_GET['url'].' is '.check_html_compliance($_GET['url']);}
else {echo '<b style="color: #00f;">Choose a domain name to validate please.</b>';}
echo "<br />\n";
$time_start = microtime(true);
// Sleep for a while
usleep(1000);
$time_end = microtime(true);
$time = $time_end - $time_start;
//echo "Rendered in $time seconds\n";
echo 'Rendered in ';
//echo substr($time, 0, 7);
echo round($time, 7);
echo ' seconds using <b style="color: #00f;">stristr</b>.';
?>
<form method="get">
<select name="url">
<option value="http://www.google.com/">www.google.com</option>
<option selected="selected" value="http://www.jabcreations.com/">www.jabcreations.com</option>
</select>
<input type="submit" value="Validate URL" />
</form>