Regular matching in the provincial urban area
Preg_match ('/(. *? Province | Autonomous Region | beijing | Tianjin city) + (. *? City | prefecture | region | division | county)) + (. *? District | county | town | township | street))/', $address, $matches);
Get an array of provincial districts
$address = "Nanshan District, Shenzhen, Guangdong province"; Preg_match ('/(. *? Provincial | Autonomous Region | beijing | tianjin))/', $address, $matches); if (count ($matches) > 1) { $province = $matches [Count ($matches)-2]; $address = Str_replace ($province, ", $address); } Preg_match ('/(. *? City, prefecture, region, Division, County))/', $address, $matches); if (count ($matches) > 1) { $city = $matches [Count ($matches)-2]; $address = Str_replace ($city, ", $address); } Preg_match ('/(. *? District | county | town | township | street))/', $address, $matches); if (count ($matches) > 1) { $area = $matches [Count ($matches)-2]; $address = Str_replace ($area, ", $address); } return [ ' Province ' = Isset ($province)? $province: ', ' city ' = Isset ($city)? $city: ', ' Area ' = Isset ($area)? $area: "," ;
Feel there should be a better way, welcome comment message
PHP regular matches provinces and cities