Snoopy-based PHP approximate perfect for website encoding For PHP crawler, get the encoding accuracy rate of 99.9%, and some can not be obtained, Daniel Perfect Code Source: Station Cloud Network www.siteyun.com First to download the Snoopy.class.php online Call Method: echo $go->getcharset ();?> [Code] Url= $url;} Open the Web site Private function open ($url) {if ($this->request!==null) {if ($this->request->status==200) {return true;} else {return false;}} else {$this->request=new Snoopy (); $this->request->fetch ($url); if ($this->request->status==200) {$ This->request->results=strtolower ($this->request->results); $charset = $this->getcharset (); if ($ charset!= "Utf-8") {if ($charset = = "windows-1252") {$this->request->results= $this->uni_decode ($this Request->results);} else {$this->request->results=mb_convert_encoding ($this->request->results, "UTF-8", $charset);}} return true;} else {return false;}}} Get site Title,keywords,descriptionpublic function Getwebinfo () {$info =array (' title ' = ' "', ' keywords ' = '", ' desc ') = = ', ' ip ' = = '); if (! $this->open ($this->url)) {return $info; exit;} Print_r ($this->request->results); Exit;preg_match ('/([^>]*) <\/title>/si ', $this->request->results, $titlematch); if (Isset ($titlematch) && Is_ Array ($titlematch) && count ($titlematch) > 0) {$info [' title '] = Strip_tags ($titlematch [1]);} Preg_match_all ('/<[\s]*meta[\s]*name= '? '). ' ([^> "]*)"? [\s]* '. ' Content= '? ([^> "]*)"? [\s]*[\/]? [\s]*>/si ', $this->request->results, $match); $ft =0;foreach ($match [1] as $MT) {if ($mt = = "keywords" | | $mt = = " Description ") {$ft = 1;}} if ($ft ==0) {preg_match_all ('/<[\s]*meta[\s]*content= "? ( [^> "]*)"? [\s]*name= '? '. ' ([^> "]*)"? [\s]*[\/]? [\s]*>/si ', $this->request->results, $match); if (Isset ($match) && Is_array ($match) && count ( $match) = = 3) {$originals = $match [0]; $names = $match [2]; $values = $match [1];if (count ($originals) = = Count ($names) &&A mp Count ($names) = = count ($values)) {$metaTags = array (); for ($i =0, $limiti =count ($names); $i < $limiti; $i + +) {$metaTags [ $names [$i]] = array (' html ' = = Htmlentities ($originals [$i]), ' ValuE ' = $values [$i]);}}} else {if (Isset ($match) && Is_array ($match) && count ($match) = = 3) {$originals = $match [0]; $names = $match [ 1]; $values = $match [2];if (count ($originals) = = Count ($names) && count ($names) = = count ($values)) {$metaTags = arr Ay (); for ($i =0, $limiti =count ($names), $i < $limiti, $i + +) {$metaTags [$names [$i]] = array (' HTML ' = Htmlentities ( $originals [$i]), ' value ' = = $values [$i]);}}} $result = Array (' metatags ' = $metaTags), if (Isset ($result [' metatags '] [' keywords '] [' value ']) {$info [' keywords ']= $result [' metatags '] [' keywords '] [' value '];} else{$info [' keywords ']= ';} if (Isset ($result [' metatags '] [' description '] [' value ']) {$info [' desc ']= $result [' metatags '] [' description '] [' Value '];} else{$info [' desc ']= ';} $domain =preg_replace ('/http\:\/\//si ', ' ', $this->url); $ip = @gethostbyname ($domain); $ip _arr=explode (".", $ip); if (count ($ip _arr) ==4) {$info [' IP ']= $ip;} return $info;} Public Function T ($string, $o) {for ($i =0; $i Open ($this->url)) {return false;exit;} First get the code from HTML Preg_match ("/ request->results, $temp)? Strtolower ($temp [1]): "", if ($temp [1]!= "") {if (In_array ($temp [1], $this->charset_arr)) {if ($temp [1]== "gb2312") {$ tmp_charset= $this->t ($this->request->results, $temp [1]), if ($tmp _charset== $temp [1]) {return $temp [1];}} else {return $temp [1];}}} if (!empty ($this->request->headers)) {//Gets the encoding $hstr=strtolower from the header (Implode (" |