<?php
$refer="http://city.qq.com"; //定义$refer
$opt=array('http'=>array('header'=>"referer: $refer")); //请求头部数组
$context=stream_context_create($opt); //创建一个发送上下文头部信息文本
$jsonurl ="http://city.qq.com/json.php?mod=search&act=page&callback=showsrchresult&jsontype=str&perpage=10&cd=610900&nl=3&xb=0&type=city&pg=1";
$jsonstr = getjson($jsonurl,$refer,$context); //调用json代理函数
echo $jsonstr; //输出json文本
//获取qq达人json数据
function getjson($url,$referer,$context)
{
$opt=array('http'=>array('header'=>"referer: $referer"));
$context=stream_context_create( $opt);
$getjsonstr =
file_get_contents( $url,false, $context);
$getjsonstr = substr($getjsonstr,0,-2);
$getjsonstr = substr($getjsonstr,15);
return $getjsonstr;
}
?>