<?php
ini_set(‘max_execution_time’, 60);//脚本最大允许执行时长祿 表示没有限制
ini_set(‘memory_limit’, ’128M’);//限制最大占用的内存 28M
ini_set(‘error_reporting’, 0);
ini_set(‘display_errors’, 0);
ini_set(‘magic_quotes_runtime’, 0);//默认为off,意为不转义从文件读取或数据库中查询获得的数据
ini_set(‘magic_quotes_sybase’, 0);//是否采用Sybase形式的自动字符串转义★★
ini_set(‘default_mimetype’, ‘text/html’);//设置默认mime类型为text/html
ini_set(‘default_charset’,'UTF-8′);//设置默认编码为UTF-8
ini_set(‘default_socket_timeout’, ’60′);//默认socket超时(祿
ini_set(‘date.timezone’, ‘UTC’);//设置时区 //date_default_timezone_set(‘UTC’);
//检查gzip加速支持情儿
if ( extension_loaded(‘zlib’) && strstr($_SERVER["HTTP_ACCEPT_ENCODING"],”gzip”) ) {
ob_start(‘ob_gzhandler’);
} else {
ob_start();
}
//header(‘Content-Type: text/html; charset=UTF-8′);
//header(‘Content-language: zh-CN’);
//header(‘Expires:-1′);
header(‘Server: gws’);
header(‘X-Powered-By: gushu’);
$str1 = array(
‘<title>Google</title>’,
‘Google 搜索</title>’,
‘www.google.com.hk’,
‘zh-TW’
);
$str2 = array(‘
<title>CrazyLemon提供Google在线翻墙搜索服务</title>’,
‘CrazyLemon提供Google在线翻墙搜索服务</title>’,
‘www.crazylemon.net/google’,
‘zh-CN’
);
//echo $_SERVER["QUERY_STRING"];
if(!empty($_SERVER["QUERY_STRING"])){
$q = str_replace(‘hl=zh-TW’,'hl=zh-CN’,$_SERVER["QUERY_STRING"]);
$url = ‘http://www.google.com.hk/search?’.$q;
}else{
$url = ‘http://www.google.com.hk/’;
}
$user_agent = $_SERVER["HTTP_USER_AGENT"];
$referer_url = ‘http://www.gushu.cn/’;
//$url 需要抓取的页面地址
//$user_agent 需要返回的user_agent信息 如“baiduspider”或“googlebot
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
//curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_REFERER, $referer_url);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
/*
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_COOKIE, $_COOKIE);
curl_setopt ($ch, CURLOPT_POST, $_POST);
*/
if(!curl_errno($ch))
{
$google =str_replace(“/search”,”/google/search”, curl_exec ($ch));
echo str_replace($str1,$str2,$google);
}
curl_close($ch);
ob_end_flush();
?>
如何把一段文本里的A标签都去掉?
preg_replace(array(“/\<a[^\>]+\>/i”,”/\<\/a\>/i”), “”, $string);
