Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- GDI+
- silverlight
- XML
- 검색
- 백신
- JavaScript
- 전기차
- 실버라이트
- WEb 2.0 Expo
- 암호화
- 성공
- 해킹
- jQuery
- C#
- ASP.NET
- Ajax
- .net
- 실버라이트2
- MS
- 개발자
- 자바스크립트
- GTD
- 리팩토링
- 구글
- COM+
- 게으름
- Web 2.0
- 형태소분석기
- hnd-7070
- Sliverlight
Archives
- Today
- Total
꿈으로 가는 작은 계단
구글에서 도시 정보 가져오기 본문
구글에서 날씨 정보를 얻어오기 위해서 필요한 국가별 도시 정보를 가져오는 클래스입니다. 간단하긴 한데, 출력 데이터가 validate 되지 않은 JSON이라서 그거 수정하는데 30분 정도 걸렸네요.(미워요 구글~~)
그 부분 메쏘드는 convertJson(한줄짜리 -_-;) 이구요, 나머지는 쉬우니까 패스~~
소스 들어갑니다.
<?php
$iso = 'KR';
$City = new CompanyCity($iso);
print_r($City->get());
class CompanyCity {
const KOURL = 'http://www.google.co.kr/ig/cities?country=';
const ENURL = 'http://www.google.com/ig/cities?country=';
const UTF8 = '&oe=UTF-8';
private $country;
private $city;
private $type = 'array'; // OR object
public function __construct($iso3166)
{
$this->country = $iso3166;
}
private static function convertJson($v)
{
return preg_replace('/(cities|name|lat|lon|code|selected|true)/', "\""."\\1"."\"", $v);
}
public function get()
{
$this->city = file_get_contents(self::KOURL.$this->country.self::UTF8);
return $this->type=='array' ? json_decode(self::convertJson($this->city), true) : json_decode(self::convertJson($this->city));
}
}
?>
입력할 때 ISO-3166-1-alpha-2 에 맞는 코드를 입력해야 출력이 제대로 나옵니다.
이제 전 퇴근을... =3=3=3
출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=61421&page=2
그 부분 메쏘드는 convertJson(한줄짜리 -_-;) 이구요, 나머지는 쉬우니까 패스~~
소스 들어갑니다.
<?php
$iso = 'KR';
$City = new CompanyCity($iso);
print_r($City->get());
class CompanyCity {
const KOURL = 'http://www.google.co.kr/ig/cities?country=';
const ENURL = 'http://www.google.com/ig/cities?country=';
const UTF8 = '&oe=UTF-8';
private $country;
private $city;
private $type = 'array'; // OR object
public function __construct($iso3166)
{
$this->country = $iso3166;
}
private static function convertJson($v)
{
return preg_replace('/(cities|name|lat|lon|code|selected|true)/', "\""."\\1"."\"", $v);
}
public function get()
{
$this->city = file_get_contents(self::KOURL.$this->country.self::UTF8);
return $this->type=='array' ? json_decode(self::convertJson($this->city), true) : json_decode(self::convertJson($this->city));
}
}
?>
입력할 때 ISO-3166-1-alpha-2 에 맞는 코드를 입력해야 출력이 제대로 나옵니다.
이제 전 퇴근을... =3=3=3
출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=61421&page=2
'소프트웨어 > JavaScript • Dhtml' 카테고리의 다른 글
| JSON API 하이재킹, Ajax Security (0) | 2009.05.21 |
|---|---|
| Javascript Packer & 암호화 - C# (0) | 2008.06.30 |
| 구글 AJAX Libraries API (0) | 2008.06.04 |
| XMLHttpRequest 번역본 2 (0) | 2008.04.22 |
| JavaScript에서 클래스를 사용할 때의 생성자 (0) | 2008.03.30 |