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
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

Unfortunately, no..

[PASS] apple ............... Result: an .... Expected: an
[PASS] dog ................. Result: a .... Expected: a
[PASS] house ............... Result: a .... Expected: a
[FAIL] hour ................ Result: a .... Expected: an
[FAIL] university .......... Result: an .... Expected: a
[PASS] yellow dog .......... Result: a .... Expected: a
[FAIL] ytterbium molecule .. Result: a .... Expected: an
[FAIL] U ................... Result: an .... Expected: a
[FAIL] M ................... Result: a .... Expected: an
[PASS] umbrella ............ Result: an .... Expected: an

@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