구글에서 날씨 정보를 얻어오기 위해서 필요한 국가별 도시 정보를 가져오는 클래스입니다. 간단하긴 한데, 출력 데이터가 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 에 맞는 코드를 입력해야 출력이 제대로 나옵니다.
http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm#holy-see-vatican
출처 : PHPSCHOOL 팁엔테크 이삼구님
그 부분 메쏘드는 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 에 맞는 코드를 입력해야 출력이 제대로 나옵니다.
http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm#holy-see-vatican
출처 : PHPSCHOOL 팁엔테크 이삼구님
Country names | ISO 3166-1-alpha-2 code |
---|---|
A | |
AFGHANISTAN | AF |
ÅLAND ISLANDS | AX |
ALBANIA | AL |
ALGERIA | DZ |
AMERICAN SAMOA | AS |
ANDORRA | AD |
ANGOLA | AO |
ANGUILLA | AI |
ANTARCTICA | AQ |
ANTIGUA AND BARBUDA | AG |
ARGENTINA | AR |
ARMENIA | AM |
ARUBA | AW |
AUSTRALIA | AU |
AUSTRIA | AT |
AZERBAIJAN | AZ |
B | |
BAHAMAS | BS |
BAHRAIN | BH |
BANGLADESH | BD |
BARBADOS | BB |
BELARUS | BY |
BELGIUM | BE |
BELIZE | BZ |
BENIN | BJ |
BERMUDA | BM |
BHUTAN | BT |
BOLIVIA | BO |
BOSNIA AND HERZEGOVINA | BA |
BOTSWANA | BW |
BOUVET ISLAND | BV |
BRAZIL | BR |
BRITISH INDIAN OCEAN TERRITORY | IO |
BRUNEI DARUSSALAM | BN |
BULGARIA | BG |
BURKINA FASO | BF |
BURUNDI | BI |
C | |
CAMBODIA | KH |
CAMEROON | CM |
CANADA | CA |
CAPE VERDE | CV |
CAYMAN ISLANDS | KY |
CENTRAL AFRICAN REPUBLIC | CF |
CHAD | TD |
CHILE | CL |
CHINA | CN |
CHRISTMAS ISLAND | CX |
COCOS (KEELING) ISLANDS | CC |
COLOMBIA | CO |
COMOROS | KM |
CONGO | CG |
CONGO, THE DEMOCRATIC REPUBLIC OF THE | CD |
COOK ISLANDS | CK |
COSTA RICA | CR |
CÔTE D'IVOIRE | CI |
CROATIA | HR |
CUBA | CU |
CYPRUS | CY |
CZECH REPUBLIC | CZ |
D | |
DENMARK | DK |
DJIBOUTI | DJ |
DOMINICA | DM |
DOMINICAN REPUBLIC | DO |
E | |
ECUADOR | EC |
EGYPT | EG |
EL SALVADOR | SV |
EQUATORIAL GUINEA | GQ |
ERITREA | ER |
ESTONIA | EE |
ETHIOPIA | ET |
F | |
FALKLAND ISLANDS (MALVINAS) | FK |
FAROE ISLANDS | FO |
FIJI | FJ |
FINLAND | FI |
FRANCE | FR |
FRENCH GUIANA | GF |
FRENCH POLYNESIA | PF |
FRENCH SOUTHERN TERRITORIES | TF |
G | |
GABON | GA |
GAMBIA | GM |
GEORGIA | GE |
GERMANY | DE |
GHANA | GH |
GIBRALTAR | GI |
GREECE | GR |
GREENLAND | GL |
GRENADA | GD |
GUADELOUPE | GP |
GUAM | GU |
GUATEMALA | GT |
GUERNSEY | GG |
GUINEA | GN |
GUINEA-BISSAU | GW |
GUYANA | GY |
H | |
HAITI | HT |
HEARD ISLAND AND MCDONALD ISLANDS | HM |
HOLY SEE (VATICAN CITY STATE) | VA |
HONDURAS | HN |
HONG KONG | HK |
HUNGARY | HU |
I | |
ICELAND | IS |
INDIA | IN |
INDONESIA | ID |
IRAN, ISLAMIC REPUBLIC OF | IR |
IRAQ | IQ |
IRELAND | IE |
ISLE OF MAN | IM |
ISRAEL | IL |
ITALY | IT |
J | |
JAMAICA | JM |
JAPAN | JP |
JERSEY | JE |
JORDAN | JO |
K | |
KAZAKHSTAN | KZ |
KENYA | KE |
KIRIBATI | KI |
KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF | KP |
KOREA, REPUBLIC OF | KR |
KUWAIT | KW |
KYRGYZSTAN | KG |
L | |
LAO PEOPLE'S DEMOCRATIC REPUBLIC | LA |
LATVIA | LV |
LEBANON | LB |
LESOTHO | LS |
LIBERIA | LR |
LIBYAN ARAB JAMAHIRIYA | LY |
LIECHTENSTEIN | LI |
LITHUANIA | LT |
LUXEMBOURG | LU |
M | |
MACAO | MO |
MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF | MK |
MADAGASCAR | MG |
MALAWI | MW |
MALAYSIA | MY |
MALDIVES | MV |
MALI | ML |
MALTA | MT |
MARSHALL ISLANDS | MH |
MARTINIQUE | MQ |
MAURITANIA | MR |
MAURITIUS | MU |
MAYOTTE | YT |
MEXICO | MX |
MICRONESIA, FEDERATED STATES OF | FM |
MOLDOVA | MD |
MONACO | MC |
MONGOLIA | MN |
MONTENEGRO | ME |
MONTSERRAT | MS |
MOROCCO | MA |
MOZAMBIQUE | MZ |
MYANMAR | MM |
N | |
NAMIBIA | NA |
NAURU | NR |
NEPAL | NP |
NETHERLANDS | NL |
NETHERLANDS ANTILLES | AN |
NEW CALEDONIA | NC |
NEW ZEALAND | NZ |
NICARAGUA | NI |
NIGER | NE |
NIGERIA | NG |
NIUE | NU |
NORFOLK ISLAND | NF |
NORTHERN MARIANA ISLANDS | MP |
NORWAY | NO |
O | |
OMAN | OM |
P | |
PAKISTAN | PK |
PALAU | PW |
PALESTINIAN TERRITORY, OCCUPIED | PS |
PANAMA | PA |
PAPUA NEW GUINEA | PG |
PARAGUAY | PY |
PERU | PE |
PHILIPPINES | PH |
PITCAIRN | PN |
POLAND | PL |
PORTUGAL | PT |
PUERTO RICO | PR |
Q | |
QATAR | QA |
R | |
RÉUNION | RE |
ROMANIA | RO |
RUSSIAN FEDERATION | RU |
RWANDA | RW |
S | |
SAINT BARTHÉLEMY | BL |
SAINT HELENA | SH |
SAINT KITTS AND NEVIS | KN |
SAINT LUCIA | LC |
SAINT MARTIN | MF |
SAINT PIERRE AND MIQUELON | PM |
SAINT VINCENT AND THE GRENADINES | VC |
SAMOA | WS |
SAN MARINO | SM |
SAO TOME AND PRINCIPE | ST |
SAUDI ARABIA | SA |
SENEGAL | SN |
SERBIA | RS |
SEYCHELLES | SC |
SIERRA LEONE | SL |
SINGAPORE | SG |
SLOVAKIA | SK |
SLOVENIA | SI |
SOLOMON ISLANDS | SB |
SOMALIA | SO |
SOUTH AFRICA | ZA |
SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS | GS |
SPAIN | ES |
SRI LANKA | LK |
SUDAN | SD |
SURINAME | SR |
SVALBARD AND JAN MAYEN | SJ |
SWAZILAND | SZ |
SWEDEN | SE |
SWITZERLAND | CH |
SYRIAN ARAB REPUBLIC | SY |
T | |
TAIWAN, PROVINCE OF CHINA | TW |
TAJIKISTAN | TJ |
TANZANIA, UNITED REPUBLIC OF | TZ |
THAILAND | TH |
TIMOR-LESTE | TL |
TOGO | TG |
TOKELAU | TK |
TONGA | TO |
TRINIDAD AND TOBAGO | TT |
TUNISIA | TN |
TURKEY | TR |
TURKMENISTAN | TM |
TURKS AND CAICOS ISLANDS | TC |
TUVALU | TV |
U | |
UGANDA | UG |
UKRAINE | UA |
UNITED ARAB EMIRATES | AE |
UNITED KINGDOM | GB |
UNITED STATES | US |
UNITED STATES MINOR OUTLYING ISLANDS | UM |
URUGUAY | UY |
UZBEKISTAN | UZ |
V | |
VANUATU | VU |
VATICAN CITY STATE | see HOLY SEE |
VENEZUELA | VE |
VIET NAM | VN |
VIRGIN ISLANDS, BRITISH | VG |
VIRGIN ISLANDS, U.S. | VI |
W | |
WALLIS AND FUTUNA | WF |
WESTERN SAHARA | EH |
Y | |
YEMEN | YE |
Z | |
ZAMBIA | ZM |
ZIMBABWE | ZW |
'인터넷관련' 카테고리의 다른 글
일본검색사이트 (0) | 2008.08.14 |
---|---|
정식판 MS Live Writers 2008 (0) | 2008.06.05 |
포토샵 모자이크 효과 처리 (0) | 2008.05.20 |
[보안] 디도스 자동공격 봇 막기 (0) | 2008.05.14 |
javascript escape,unescape by PHP (0) | 2008.05.14 |
특정 페이지나 주소 URL에서 애드센스광고(AdSense) 숨기기 및 차단하기 (0) | 2008.04.26 |
플래시 9.0.124 소켓관련 변경사항 (0) | 2008.04.15 |
google 에서 제공하는 날씨 정보 (0) | 2008.04.15 |