In PHP, timezone_location_get() returns location information for a time zone, such as its country code and its latitude and longitude.
The result is an array with four keys: country_code, latitude, longitude and comments. It only works with identifier-style zones like Europe/Paris. For zones created from an offset or an abbreviation, it returns false. It is the procedural version of DateTimeZone::getLocation().
Syntax
Call timezone_location_get() with the values you need. Start with this line.
PHP
$loc = timezone_location_get($tz);
Call
What it does
timezone_location_get($tz)
Returns the location array for the DateTimeZone object $tz.
timezone_location_get($tz)['country_code']
Reads just the two-letter country code.
$tz->getLocation()
The object-oriented version that returns the same array.
Always check the result before you use it, because the function returns false for zones that have no location, such as a plain offset like +02:00.
UTC is a valid identifier, so PHP returns an array for it.
Because UTC is not tied to a country, the country code is the placeholder ??.
The zone +02:00 is only an offset and has no location data.
For that kind of zone the function returns false, so always test for false before reading the array.
Frequently Asked Questions
It returns an array with country_code, latitude, longitude and comments for a time zone, or false when the zone has no location information.
This happens when the DateTimeZone was created from a UTC offset such as +02:00 or from an abbreviation such as EST. Only identifier-based zones like Europe/Paris carry location data.
They are the coordinates of a representative place for the time zone, usually a main city. They are not precise borders.
Yes. The function is the procedural alias of the DateTimeZone::getLocation() method and returns the same result.
It means the time zone does not belong to a single country. UTC is the usual example.