code postal

[PHP] fonction code du département à partir d'un code postal

function getDepartementCodeFromCP($cp) {
                $cp = str_pad(str_replace(' ', '', $cp), 5, '0', STR_PAD_LEFT);
	        $dep_code = substr($cp, 0, 2);
	        if($dep_code == '20') {
	            if((int)$cp < 20200 || in_array((int)$cp, array(20223,20900))){
	                $dep_code = '2A';
	            }else {
	                $dep_code = '2B';
	            }
	        }
	
	        if((int)$dep_code > 95) {
	            $dep_code = substr($cp, 0, 3);
	        }
	
	        return $dep_code;
	    }
Subscribe to RSS - code postal