Skip to content

Instantly share code, notes, and snippets.

@samstarling
Created February 21, 2011 22:14
Show Gist options
  • Save samstarling/837805 to your computer and use it in GitHub Desktop.
Save samstarling/837805 to your computer and use it in GitHub Desktop.
Gets your a's/an's correct. Originally from http://james.cridland.net/code/
<?
// Usage:
echo "I have ".return_indefinitearticle("apple")." apple, and ".return_indefinitearticle("slice of bread")." slice of bread.";
function return_indefinitearticle($thing) {
return (preg_match('/^[aeiou]|s\z/i', strtolower($thing))) ? "an" : "a";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment