/* * 處理地址匹配出省市區 */ function handleAddress($address){ preg_match('/(.*?(省|自治區|北京市|天津市))/', $address, $matches); if(count($matches) > 1){ $province = $matches[count($matches) - 2]; $address = str_replace($province, '', $address); } preg_match('/(.*?(市|自治州|地區|區划|縣))/', $address, $matches); if(count($matches) > 1){ $city = $matches[count($matches) - 2]; $address = str_replace($city, '', $address); } preg_match('/(.*?(區|縣|鎮|鄉|街道))/', $address, $matches); if(count($matches) > 1){ $area = $matches[count($matches) - 2]; $address = str_replace($area, '', $address); } return array('province'=>isset($province) ? $province : '','city' => isset($city) ? $city : '','area' => isset($area) ? $area : ''); }
轉載鏈接:https://www.cnblogs.com/yimingwang/p/8855650.html
