mirror of https://github.com/dnomd343/echoIP
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							35 lines
						
					
					
						
							833 B
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							35 lines
						
					
					
						
							833 B
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								// 数据来源:country.db
							 | 
						|
								// 请求方式:getCountry($code)
							 | 
						|
								// 返回格式:
							 | 
						|
								// {
							 | 
						|
								//     "code": 国家的2位编码
							 | 
						|
								//     "en": 国家英文名称
							 | 
						|
								//     "cn": 国家中文名称
							 | 
						|
								// }
							 | 
						|
								
							 | 
						|
								class countryDB extends SQLite3 {
							 | 
						|
								    function __construct() {
							 | 
						|
								        $this->open('country.db'); // 国家地区缩写及代号数据库
							 | 
						|
								    }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								function getCountry($code) { // 根据两位国家代码获取英文与中文全称
							 | 
						|
								    if ($code == null) {
							 | 
						|
								        return null;
							 | 
						|
								    }
							 | 
						|
								    $db = new countryDB;
							 | 
						|
								    $raw = $db->query('SELECT * FROM main WHERE alpha_2=\'' . $code . '\';')->fetchArray(SQLITE3_ASSOC);
							 | 
						|
								    $data['code'] = $code;
							 | 
						|
								    if ($raw) {
							 | 
						|
								        $data['en'] = $raw['name_en'];
							 | 
						|
								        $data['cn'] = $raw['name_cn'];
							 | 
						|
								    } else {
							 | 
						|
								        $data['en'] = null;
							 | 
						|
								        $data['cn'] = null;
							 | 
						|
								    }
							 | 
						|
								    return $data;
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								?>
							 |