Generating a SOAP request in PHP to W3C Validator?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Generating a SOAP request in PHP to W3C Validator?

Post by JAB Creations »

Speed Comparison

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>
stristr

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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Generating a SOAP request in PHP to W3C Validator?

Post by RobertGonzalez »

Is it doing what you expect it to do?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Generating a SOAP request in PHP to W3C Validator?

Post by JAB Creations »

CSS Validator

Got this to work, I think I'll head over to the critique forum and share this with those not interested in my typical twenty post long threads. :mrgreen:

Code: Select all

<?php
function check_html_compliance($url) {
$referer = $url;
 
$ch = curl_init('http://jigsaw.w3.org/css-validator/validator?uri='.$_GET['url']);
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, 'Congratulations! No Error Found.') == TRUE)
{
$result = '<b style="color: #0f0;">Valid!</b>';
}
else if (stristr($output, 'Sorry! We found the following errors') == TRUE)
{
$result = '<b style="color: #f00;">Invalid!</b>';
}
else {
$result = '<b style="color: #f00;">Error validating CSS, contact admin please.</b>';
}
 
 
return $result;
}
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 ';
echo round($time, 7);
echo ' seconds using <b style="color: #00f;">stristr</b>.';
?>
<form method="get">
<select name="url">
<option selected="selected" value="http://www.w3.org/">www.w3.org</option>
<option value="http://us2.php.net/stristr">DevNetwork</option>
<option value="http://www.google.com/">www.google.com</option>
<option value="445566">445566</option>
<option value="http://www.jabcreations.com/">www.jabcreations.com</option>
</select>
<input type="submit" value="Validate URL" />
</form>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Generating a SOAP request in PHP to W3C Validator?

Post by JAB Creations »

Yes, everything seems to be working fine.

...and thanks for your suggestions. While vague they were able to turn my attention to cURL which I found examples and documentation that I could grasp and slowly manipulate.

Also...ha now I could technically write site scrappers. LoL
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Generating a SOAP request in PHP to W3C Validator?

Post by JAB Creations »

I've posted a new thread in the critique forum.
Post Reply