Skip to content

Instantly share code, notes, and snippets.

@jamescridland
Forked from samstarling/indefinite_article.php
Created February 21, 2011 23:01
Show Gist options
  • Save jamescridland/837874 to your computer and use it in GitHub Desktop.
Save jamescridland/837874 to your computer and use it in GitHub Desktop.
A little bit of PHP to return "a" and "an" correctly.
<?
// 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";
}
?>
@vmadman
Copy link

vmadman commented Aug 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment