先到網路下載Snoopy.class.php
呼叫方法:
複製程式碼 程式碼如下:
require'lib/Snoopy.class. class.php';//包含下面程式碼
$go=new WebCrawl('http://www.baidu.com');
echo $go->getCharset();
?>
複製代碼 代碼如下:
class WebCrawl
{
private $url;
私人$請求;
public $charset_arr=array(
'gb2312',
'utf-8',
'big5',
'gbk',
'ascii',
, 36' 'ibm437',
'ibm500',
'asmo-708',
'dos-720',
'ibm737',
'ibm775',
'ibm850',
'ibm775',
'ibm850',
'ibm85'm ibm857',
'ibm00858',
'ibm861',
'ibm860',
'dos-862',
'ibm863',
'ibm864',
'ibm865',
'cp866', 869', 70' ,
'windows-874'、
'cp875'、
'shift_jis'、
'ks_c_5601-1987'、
'ibm1026'、
'ibm01047'、30m'ibm' 01041 ',
'ibm01042',
'ibm01043',
'ibm01044',
'ibm01045',
'ibm01046',
'ibm01047',
'ibm01046',
'ibm01047',
'ib ',
' unicodefffe'、
'windows-1250'、
'windows-1251'、
'windows-1252'、
'windows-1253'、
'windows-1254'、
'window
'windows-1254'、
'window ',
'windows-1257',
'windows-1258',
'johab',
'macintosh',
'x-mac-japanese',
'x-mac-chine
'x-mac-japanese',
'x-mac-chine
'x-mac-japanoo 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 -土耳其語言',
'x-mac-克羅埃西亞語',
'x-chinese-cns',
'x-cp20001',
'x-chinese-eten',
'x-cp20003', 0x-cp2000x-cp ',
'x-cp20005',
'x-ia5',
'x-ia5-德國',
'x-ia5-瑞典語',
'x-ia5-挪威語',
'us-ascii ',
'x-cp20261',
'x-cp20269',
'ibm273',
'ibm277',
'ibm278',
'ibm280',
'ibm284',
'ibm285', 90' ,
'ibm290', m420',
'ibm423'、
'ibm424'、
'x-ebcdic-koreanextended'、
'ibm-thai'、
'koi8-r'、
'ibm81'
'ibm905'、
'ibm00924'、
'x-cp20936'、
'x-cp20949'、
'cp1025'、
'koi8-u'、
'iso-8598,85985' -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-859- 859- 859- i',
'iso- 2022-jp',
'csiso2022jp',
'iso-2022-jp',
'iso-2022-kr',
'x-cp50227', jp
' 'euc-cn',
'euc-kr',
'hz-gb-2312',
'gb18030',
'x-iscii-de',
'x-iscii-be',
'x -isis -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'
);
公用函數 __construct($url)
{
$this->url=$url;
}
//開啟網站
胰臟函數 open($url)
{
if($this->request!==null)
{
if($this->request->status==200)
{
if($this->request->status==200)
{
返回真;
}
否則
{
回傳 false;
}
}
else
{
$this->request=new Snoopy();
$this->請求->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->請求->結果=$this->uni_decode($此->請求->結果);
}
else
{
$this->request->results=mb_convert_encoding($this->request->results,"UTF-8",$charset);
}
}
返回;
}
否則
{
回傳false;
}
}
}
//取得網站標題、關鍵字、描述
public function getWebinfo()
{
{
,
'keywords'=>'',
'desc'=>'',
'ip'=>''
);
if(!$this->open($this->url)){return $ info;exit;}
// print_r($this->request->results);exit;
preg_match('/