function location_province_code in Location 7.3
Same name and namespace in other branches
- 5.3 location.inc \location_province_code()
- 6.3 location.inc \location_province_code()
- 7.5 location.inc \location_province_code()
- 7.4 location.inc \location_province_code()
Get a province code from a code or full name and a country.
3 calls to location_province_code()
- location_handler_filter_location_province::query in handlers/
location_handler_filter_location_province.inc - Add this filter to the query.
- location_search_validate in contrib/
location_search/ location_search.module - Validate callback.
- _location_geo_logic in ./
location.module - Perform geocoding logic, etc., prior to storing in the database.
File
- ./
location.inc, line 643 - Public API for the Location module.
Code
function location_province_code($country = 'us', $province = 'xx') {
// An array of countries is useful if someone specified multiple countries
// in an autoselect for example.
// It *is* possibly ambiguous, especially if the province was already a code.
// We make an array here for single (the usual case) for code simplicity reasons.
if (!is_array($country)) {
$country = array(
$country,
);
}
$p = strtoupper($province);
foreach ($country as $c) {
if ($c == 'xx') {
return $province;
}
$provinces = location_get_provinces($c);
foreach ($provinces as $k => $v) {
if ($p == strtoupper($k) || $p == strtoupper($v)) {
return $k;
}
}
}
return '';
}