Chinese city, district/county administrative names are fully converted to abbreviations

 

For the best results please download the attachment. . .

 

 

<meta charset="utf-8">
<?PHP


header("Content-type: text/html; charset=utf-8");

 

$a='110000Beijing
110100 Beijing
110101 Dongcheng District
110102 Xicheng District
110105 Chaoyang District
110106 Fengtai District
110107 Shijingshan District
110108 Haidian District
110109 Mentougou District
110111 Fangshan District
110112 Tongzhou District
110113 Shunyi District
.............
..........';

/* Administrative division name:
flag -- ignore
city
Area
County
Union
State
*/
$b = explode("\n",$a);
$new = array();
foreach($b as $row){
	$x = $row;
	$code = trim(substr($x,0,6));
	$name = trim(substr($x,6));
	$k_2 = substr($code,4);
	if(strlen($name)>6 && $k_2 == '00'){  
		if(preg_match("/市$/", $name)){
			$name = preg_replace("/市$/","", $name);
		}
		if(preg_match("/州$/", $name) && strlen($name)>6){
			$name = preg_replace("/州$/","", $name);
		}
	}
	$new[$code] = $name;
}
foreach($new as $k => $v){
	$k_4 = substr($k,0,4);
	$k_2 = substr($k,4);
	if($k_2 != '00'){//If it is a child
		//Determine whether the first two words of this level are the same as the first two words of the parent
		if(mb_substr($v,0,6) != mb_substr($new[$k_4.'00'],0,6)){
			if(strlen($v)>6){
				if(preg_match("/市$/", $v)){
					$new[$k] = preg_replace("/市$/","", $v);
				}  
				if(preg_match("/区$/", $v)
					&& substr_count($v,'municipal district') == 0
					&& substr_count($v,'矿区') == 0
					&& substr_count($v,'市区') == 0
					&& substr_count($v,'新区') == 0
					){
					$new[$k] = preg_replace("/区$/","", $v);
					//echo '__'.$name.'<HR>';  
				}  
				if(preg_match("/县$/", $v)){
					$new[$k] = preg_replace("/县$/","", $v);
					//echo '__'.$name.'<HR>';
				}
			}
		}else{// If the first two words of this level = the first two words of the parent
			//if($k_2 == '01' && preg_match("/市$/", $v)){
				//$new[$k] = preg_replace("/市$/","市区", $v);
			//}
		}
	}
}

foreach($new as $k => $v){
	echo '$re["'.$k.'"] = "'.$v.'";'.'<BR>';
	
}



 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326820005&siteId=291194637