ip geolocation api에서 city
속성을 가져 오려고합니다. 이 API에서 반환 무엇 샘플 : PHP if else php 필드가 비어 있는지 테스트합니다.
내 코드
{"as":"AS38484 Virgin Broadband VISP","city":"Adelaide","country":"Australia","countryCode":"AU","isp":"iseek Communications","lat":-27,"lon":133,"org":"iseek Communications","query":"1.178.0.144","region":"","regionName":"","status":"success","timezone":"","zip":""}
$query = '{"as":"AS38484 Virgin Broadband VISP","city":"Adelaide","country":"Australia","countryCode":"AU","isp":"iseek Communications","lat":-27,"lon":133,"org":"iseek Communications","query":"1.178.0.144","region":"","regionName":"","status":"success","timezone":"","zip":""}';
$query = @unserialize($query);
if($query && $query['status'] == 'success') {
if(!empty($query['city'])) {
$city = $query['city'];
// routine that uses $city gets called
} else {
$lat = $query['lat'];
$lon = $query['lon'];
// routine that uses $lat, $lon gets called
}
}
기본적으로, if(!empty($query['city']))
가 예상대로 작동하지 않는이 (내가 아는 정말 것이라고, 내가 사용하고 있지 PHP는 지난 주). 또한 if 문 앞에 $city
을 설정하고 if($city != '')
을 테스트하려고했습니다.
질문 : 조건 조합을 찾지 못하고 도시 속성을 city
으로 설정합니까? 도시 속성이 없으면 else 부분을 건너 뛰고 lat
/lon
을 설정하지 않습니다.
참고 : city
및 lat
/lon
사이의 차별에 대한 이유는 모든 IP 하나를 제공 할 수있는 날씨 내가 쿼리하고 API를 city
을 선호하지만,하지 않습니다.
감사
또한 무엇이 질문입니까? – Rizier123
세미콜론이 코드에 있습니다. :) 도시 속성을 찾을 수없는 문제는 미안합니다. – Lanzafame