PHP 處理地址匹配出省市區


/* 
 * 處理地址匹配出省市區 
 */
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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM