Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

네이버 지도 API XML Parsing때 PHP file_get_contents 대체

2012-08-09 by 편리

이전에 작업했던 것인데 네이버 지도API를 이용해 주소의 좌표 값을 받아오는 코드가 있었다.

이번에도 사용하려고 해보니 file_get_contents() 함수를 사용할 수가 없어 어찌해야할지 머리를 쥐어짰는데

다행히 구글신의 도움으로 해결을 할 수가 있었다. curl 을 이용하는 방법으로 아래 사이트를 참고하면 된다.

참고 사이트 : http://stackoverflow.com/questions/5979314/how-to-use-fsockopen-to-load-a-url-from-an-xml-sitemap

위 내용을 이용해서 아래처럼 코드를 작성했더니 좌표 값을 정상적으로 받아올 수가 있었다.

// 해당주소의 네이버 지도 좌표
$source =”http://openapi.map.naver.com/api/geocode.php?key=” . $naver_api_key . “&encoding=utf-8&coord=tm128&query=”;

$source .= RFCUrlEncode($address);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ($ch);
curl_close ($ch);

$parser = new XMLParser($xml);

$parser->Parse();

$xCoord = (int)$parser->document->item[0]->point[0]->x[0]->tagData;
$yCoord = (int)$parser->document->item[0]->point[0]->y[0]->tagData;

그리고 위 코드에서 사용된  RFCUrlEncode 함수는 아래와 같다.

// RFC 3986 urlencode
function RFCUrlEncode($string) {
    $entities = array(‘%21’, ‘%2A’, ‘%27’, ‘%28’, ‘%29’, ‘%3B’, ‘%3A’, ‘%40’, ‘%26’, ‘%3D’, ‘%2B’, ‘%24’, ‘%2C’, ‘%2F’, ‘%3F’, ‘%25’, ‘%23’, ‘%5B’, ‘%5D’);
    $replacements = array(‘!’, ‘*’, “‘”, “(“, “)”, “;”, “:”, “@”, “&”, “=”, “+”, “$”, “,”, “/”, “?”, “%”, “#”, “[“, “]”);
    return str_replace($entities, $replacements, urlencode($string));
}

XML Parser 는 http://www.criticaldevelopment.net/xml/ 를 접속해보면 된다.

Post navigation

Previous Post:

출입문이 깨지는 일

Next Post:

역시 월요일은 힘들다

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes