Skip to content

Instantly share code, notes, and snippets.

@R2ZER0
Created February 21, 2013 13:59
Show Gist options
  • Save R2ZER0/5004902 to your computer and use it in GitHub Desktop.
Save R2ZER0/5004902 to your computer and use it in GitHub Desktop.
<?php
function matchAirport($str)
{
$result = array();
if(preg_match('/\(([A-Z]{3})\)\s-\s[A-Z]{2}/', $str, $matches))
{
$result["type"] = "airport";
$result["iata_code"] = $matches[1];
}
else if(preg_match('/All\sof\s(.+)\s\(([A-Z]{2})\)/', $str, $matches))
{
$result["type"] = "city";
$result["city"] = $matches[1];
$result["country_id"] = $matches[2];
}
else if(preg_match('/All\sof\s(.+)/', $str, $matches))
{
$result["type"] = "country";
$result["country"] = $matches[1];
}
else
{
$result["type"] = "none";
}
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment