日期:2014-05-16 浏览次数:20513 次
public function set_title()
{
// 获取进来URL
$url = $_POST['url'];
// $url = "www.pcauto.com.cn"; 抓不到!
//一连串的curl设置
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_ENCODING,'gzip');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$content_source = curl_exec($ch);
curl_close($ch);
//获取抓到内容的编码格式
$encode = mb_detect_encoding($content_source, array('GB2312','GBK','UTF-8','ASCII'));
//转码
$content_source = iconv($encode, 'utf-8//IGNORE',$content_source);
//截取<title>
if(preg_match("/<title>(.*?)<\/title>/i",$content_source,$title))
{
echo $title[1];
}
else
{
echo '拉取标题失败';
}
}