We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 03/08/08


Tagged

html function validate


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

wbowers


check html compliance


Published in: PHP 


  1. <?php
  2. function check_html_compliance($url) {
  3. $query_string = '';
  4. foreach($_GET as $key => $val)
  5. $query_string .= '&' . $key . '=' . $val;
  6. if($query_string != '') {
  7. $query_string = substr($query_string,1);
  8. $referer = $url . '?' . $query_string;
  9. } else
  10. $referer = $url;
  11. $ch = curl_init('http://validator.w3.org/check?uri=referer');
  12. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  13. curl_setopt($ch,CURLOPT_REFERER,$referer);
  14. curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  15. curl_setopt($ch,CURLOPT_TIMEOUT,30);
  16. $output = curl_exec($ch);
  17. curl_close($ch);
  18.  
  19. if(eregi('This page is valid',$output)) {
  20. $start = strpos($output,'&lt;p&gt;') + 9;
  21. $end = strpos($output,'&lt;/p&gt;') - $start;
  22. $retval = html_entity_decode(substr($output,$start,$end));
  23. } else {
  24. $retval = 'Not Valid Code';
  25. }
  26.  
  27. return $retval;
  28. }
  29. ?>

Report this snippet 

You need to login to post a comment.