Pogledajte određenu poruku
Staro 23. 08. 2011.   #3
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

Jeste i nije, nisam dobru klasu pasteovao...

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];
    }
    

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