get current date only php | dynamic sitemap


Check if a String represents a Valid Timezone with PHP

Sometimes you want to check if a string represents a valid timezone. Using PHP versions greater than 5.2, timezone_identifiers_list() could be a solution.

Take a look in the following function:

 * Check if a string is a valid timezone
 * timezone_identifiers_list() requires PHP >= 5.2
 * @param string $timezone
 * @return bool
function isValidTimezone($timezone) {
	return in_array($timezone, timezone_identifiers_list());


From PHP manual

Sign-up for our free email newsletter. Get updates when new tutorials and tips are published. You can unsubscribe anytime with a click.

Your comments are welcomed!

This site actively encourages commenting on any post. Comments are not pre-moderated, but this community does not tolerate direct or indirect attacks, name-calling or insults. Please, read terms of use and Comment Policy at privacy policy.

More tips