Snoopy pictures based on Snoopy PHP approximate perfect code for website encoding

Source: Internet
Author: User
Tags php online
First to download the Snoopy.class.php online
Call Method:

Copy the Code code as follows:


Require ' lib/snoopy.class.php ';
Require ' lib/webcrawl.class.php ';//contains the following code
$go =new webcrawl (' http://www.baidu.com ');
echo $go->getcharset ();
?>


Copy the Code code as follows:


Class Webcrawl
{
Private $url;
Private $request;
Public $charset _arr=array (
' gb2312 ',
' Utf-8 ',
' Big5 ',
' GBK ',
' ASCII ',
' cp936 ',
' ibm037 ',
' ibm437 ',
' Ibm500 ',
' asmo-708 ',
' dos-720 ',
' ibm737 ',
' ibm775 ',
' ibm850 ',
' ibm852 ',
' ibm855 ',
' ibm857 ',
' ibm00858 ',
' ibm861 ',
' ibm860 ',
' dos-862 ',
' ibm863 ',
' ibm864 ',
' ibm865 ',
' cp866 ',
' ibm869 ',
' ibm870 ',
' windows-874 ',
' cp875 ',
' Shift_JIS ',
' ks_c_5601-1987 ',
' ibm1026 ',
' ibm01047 ',
' ibm01047 ',
' ibm01040 ',
' ibm01041 ',
' ibm01042 ',
' ibm01043 ',
' ibm01044 ',
' ibm01045 ',
' ibm01046 ',
' ibm01047 ',
' ibm01048 ',
' ibm01049 ',
' Utf-16 ',
' Unicodefffe ',
' Windows-1250 ',
' windows-1251 ',
' windows-1252 ',
' windows-1253 ',
' windows-1254 ',
' windows-1255 ',
' Windows-1256 ',
' windows-1257 ',
' windows-1258 ',
' Johab ',
' Macintosh ',
' X-mac-japanese ',
' X-mac-chinesetrad ',
' X-mac-korean ',
' X-mac-arabic ',
' X-mac-hebrew ',
' X-mac-greek ',
' X-mac-cyrillic ',
' X-mac-chinesesimp ',
' X-mac-romanian ',
' X-mac-ukrainian ',
' X-mac-thai ',
' X-mac-ce ',
' X-mac-icelandic ',
' X-mac-turkish ',
' X-mac-croatian ',
' X-chinese-cns ',
' X-cp20001 ',
' X-chinese-eten ',
' X-cp20003 ',
' x-cp20004 ',
' X-cp20005 ',
' X-ia5 ',
' X-ia5-german ',
' X-ia5-swedish ',
' X-ia5-norwegian ',
' Us-ascii ',
' x-cp20261 ',
' x-cp20269 ',
' ibm273 ',
' ibm277 ',
' ibm278 ',
' ibm280 ',
' ibm284 ',
' ibm285 ',
' ibm290 ',
' ibm420 ',
' ibm423 ',
' ibm424 ',
' X-ebcdic-koreanextended ',
' Ibm-thai ',
' Koi8-r ',
' ibm871 ',
' ibm880 ',
' ibm905 ',
' ibm00924 ',
' x-cp20936 ',
' x-cp20949 ',
' cp1025 ',
' Koi8-u ',
' Iso-8859-1 ',
' Iso-8859-2 ',
' Iso-8859-3 ',
' Iso-8859-4 ',
' Iso-8859-5 ',
' Iso-8859-6 ',
' Iso-8859-7 ',
' Iso-8859-8 ',
' Iso-8859-9 ',
' Iso-8859-13 ',
' Iso-8859-15 ',
' X-europa ',
' Iso-8859-8-i ',
' Iso-2022-jp ',
' Csiso2022jp ',
' Iso-2022-jp ',
' Iso-2022-kr ',
' x-cp50227 ',
' Euc-jp ',
' EUC-CN ',
' Euc-kr ',
' hz-gb-2312 ',
' GB18030 ',
' X-iscii-de ',
' X-iscii-be ',
' X-iscii-ta ',
' X-iscii-te ',
' X-iscii-as ',
' X-iscii-or ',
' X-iscii-ka ',
' X-iscii-ma ',
' X-iscii-gu ',
' X-iscii-pa ',
' Utf-7 ',
' Utf-32 ',
' Utf-32be '
);
Public function __construct ($url)
{
$this->url= $url;
}
Open 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,description
Public 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>([^>]*) <\/title>/si ', $this->request->results, $titlematch);</title>
if (Isset ($titlematch) && Is_array ($titlematch) && count ($titlematch) > 0)
{
$info [' title '] = Strip_tags ($titlematch [1]);
}
Preg_match_all ('/<[\s]*meta[\s]*name= '? '). ' ([^> "]*)"? [\s]* '. ' C | | $MT = = "description")
{
$ft = 1;
}
}
if ($ft ==0)
{
Preg_match_all ('/<[\s]*meta[\s]*c/ 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))
{
Get the code from the header
$hstr =strtolower (Implode ("| | |", $this->request->headers));
Preg_match ("/charset=[^\w]?" ( [-\w]+)/is ", $hstr, $lang)? Strtolower ($lang [1]): "";
if ($lang [1]!= "")
{
return $lang [1];
}
}
$encode _arr=array ("UTF-8", "GB2312", "GBK", "BIG5", "ASCII", "EUC-JP", "Shift_JIS", "CP936", "iso-8859-1", "JIS", " Eucjp-win "," Sjis-win ");
$encoded =mb_detect_encoding ($this->request->results, $encode _arr);
if ($encoded)
{
Return Strtolower ($encoded);
}
Else
{
return false;
}
}
}
?>

The above describes the Snoopy image based on the Snoopy PHP approximate perfect to obtain the Code of the website encoding, including the Snoopy picture aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.