Pogledajte određenu poruku
Staro 15. 02. 2012.   #1
webarto
expert
Grand Master
 
Avatar webarto
 
Datum učlanjenja: 11.04.2010
Poruke: 998
Hvala: 141
959 "Hvala" u 153 poruka
webarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished road
Default W3C Validator PHP Class

PHP kôd:
class W3C{

    
/**
     * @author Webarto.com
     * @copyright 2011
     */
     
    
public function check($url)
    {
        
        
$html $this->curl("http://validator.w3.org/check?uri=$url");
        
$html strip_tags($html);
        
$html str_replace(array("\t""\n"), ""$html);
        
$html preg_replace("#(\s){1,}#is""\\1"$html);

        
$result["url"] = $url;
        
$result["result"] = $this->match("Result: (.*?) Address"$html);
        
$result["encoding"] = $this->match("Encoding: (.*?) \(detect automatically\)"$html);
        
$result["doctype"] = $this->match("Doctype: (.*?) \(detect automatically\)"$html);
        
$result["valid"] = (strpos($html"[Valid]") !== false)? truefalse;

        return 
$result;
    
    }
    
    public function 
boolean($url)
    {

        
$return false;
        
        
$curl curl_init();
        
curl_setopt($curlCURLOPT_URL"http://validator.w3.org/check?uri=$url");
        
curl_setopt($curlCURLOPT_HEADER1);
        
curl_setopt($curlCURLOPT_NOBODY1); 
        
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
        
$data curl_exec($curl);
        
curl_close($curl);
        
        
$status $this->match("X-W3C-Validator-Status: ([\S]+)"$data);
        if(
$status == "Valid"){
            
$return true;
        }else{
            
$return false;
        }
        return 
$return;
    
    }

    private function 
curl($url)
    {
        
$curl curl_init();
        
curl_setopt($curlCURLOPT_URL$url);
        
curl_setopt($curlCURLOPT_ENCODING"gzip");
        
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
        
$data curl_exec($curl);
        
curl_close($curl);
        return 
$data;
    }
        
    private function 
match($regex$string)
    {
        
preg_match("#$regex#is"$string$matches);
        return 
$matches[1];
    }
    

Full check.

PHP kôd:
include_once 'class.w3c.php';
$w3c = new W3C;
$result $w3c->check("http://example.com");
$valid = ($result["valid"] == true) ? "Valid""Invalid";
echo 
"Website {$result[url]} is W3C {$valid} ({$result[result]}), checked as {$result[doctype]} and with {$result[encoding]} encoding."
Quick check.
PHP kôd:
include_once 'class.w3c.php';
$w3c = new W3C;

$uris = array(
    
"http://activeden.net/"
    
"http://audiojungle.net/"
    
"http://themeforest.net/"
    
"http://videohive.net/"
    
"http://graphicriver.net/"
    
"http://3docean.net/",
    
"http://codecanyon.net/",
    
"http://marketplace.tutsplus.com/"
);

foreach(
$urls as $url){
    
$x $w3c->boolean($url);
    echo (
$x == true)? "{$url} is Valid!""{$url} is Invalid!";
    echo 
'<br />';

__________________
Github // LinkedIn // PHP // ZCE // Stackoverflow PHP // Site5 Web Hosting
webarto je offline   Odgovorite uz citat