当我尝试解析我的地理编码链接时,由于 amp; 陈述。在我“json_decode”字符串之前,我有一个名为 www.something.com/something?bla=bla&sensor=true 的链接,但是当我将它作为参数发送到函数时,它的 & 字符被转换为&
. 像这样的链接
http://maps.googleapis.com/maps/api/geocode/json?address=Bekirdere,%20%C4%B0zmir&sensor=true
工作正常,但链接喜欢
http://maps.googleapis.com/maps/api/geocode/json?address=Bekkirdere,%20%C4%B0zmit&sensor=true
没有给出任何结果。(&
转换为&
)
我怎样才能阻止它被转换?
我的解析器功能:
function get_url_contents($url)
{
$url = str_replace(' ', '%20', $url);
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
function __construct($url)
{
$json = $this->get_url_contents($url);
$this->_jsonArray = json_decode($json, true);
}