function filterCity($address)
{
$province = '火星';
$city = '火星';
if (preg_match("|(.*)省(.*)|", $address, $matches)) {
$province = $matches[1];
$city = $matches[2];
} else if (preg_match("|(.*)自治区(.*)|", $address, $matches)) {
$map = [
'广西壮族' => '广西',
'新疆维吾尔' => '新疆',
'宁夏回族' => '宁夏',
];
$province = isset($map[$matches[1]]) ? $map[$matches[1]] : $matches[1];
$city = $matches[2];
} else if (preg_match("|(.*)市|", $address, $matches)) {
$province = $matches[1];
$city = $matches[1];
} else if (preg_match("|(.*)特别行政区|", $address, $matches)) {
$province = $matches[1];
$city = $matches[1];
}
if(strpos($city, '市')) {
$city = str_replace('市', '', $city);
}
if(strpos($city, '自治州')) {
$city = str_replace('自治州', '', $city);
$map = [
'西双版纳',
'博尔塔拉',
'黔东南',
'黔西南',
'巴音郭楞',
'克孜勒苏柯尔克孜',
'博尔塔拉',
'伊犁哈萨克'
];
foreach($map as $value) {
if(strpos($city, $value) !== false) {
$city = $value;
}
}
if(!in_array($city, $map)) {
$city = mb_substr($city, 0, 2);
}
}
$data = [
'province' => $province,
'city' => $city
];
return $data;
}