2011-03-31 6 views
1

누군가가이 문제를 해결할 수 있습니까? 나는 PHP 위도와 경도로 주소를 알아야한다.프록시 문제! PHP에서 simplexml_load_file을 사용하여

내가 뭐하고 있었 :

$ 주소를 =를 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 : 이름 해상도 임시 실패

프록시를 구성해야이 방식으로 변경해야한다고 생각합니다.

$ address = urlencode ('my address');

$ 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, 'my + port');

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

curl_close ($ ch);

curl_exec으로 전화하면 차단 된 것으로 보입니다.

답변

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); 
0

함수 내에서 마지막 줄 수 있어야 코드

curl_close ($ch); 

을 확인

관련 문제