【问题标题】:proxy prob!em using simplexml_load_file in php在 php 中使用 simplexml_load_file 代理问题!
【发布时间】:2011-07-26 19:06:42
【问题描述】:

有人可以帮我解决这个问题吗? 我需要知道一个地址的 php 纬度和经度。

我在做:

$address = urlencode('我的地址');

$lat_lng = simplexml_load_file("http://maps.google.com/maps/api/geocode/xml?address={$address}&sensor=false");

但我收到了这个警告:

消息:simplexml_load_file() [function.simplexml-加载文件]: php_network_getaddresses:getaddrinfo failed:名称暂时失败 分辨率

我觉得需要配置代理所以改成这样:

$address = urlencode('我的地址');

$ch = curl_init("http://maps.google.com/maps/api/geocode/xml?address={$address}&sensor=false");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_PROXY, 'my_proxy);

curl_setopt($ch, CURLOPT_PROXYPORT, '我的+端口');

$lat_lng = simplexml_load_string(curl_exec($ch));

curl_close($ch);

当我拨打curl_exec时,它似乎被阻止了。

【问题讨论】:

    标签: php simplexml


    【解决方案1】:

    先尝试无代理设置,可能是代理配置错误。

    function curl($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_close ($ch);
        return curl_exec($ch);
    }
    
    $address = urlencode($address);
    $data = curl("http://maps.google.com/maps/api/geocode/xml?address=$address&sensor=false"); 
    $lat_lng = simplexml_load_string($data);
    

    【讨论】:

      【解决方案2】:

      检查你的代码

      curl_close ($ch); 
      

      应该是函数内的最后一行

      【讨论】:

        猜你喜欢
        • 2012-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-11
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        相关资源
        最近更新 更多