Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
Created October 3, 2011 11:58
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 robwilkerson/1258957 to your computer and use it in GitHub Desktop.
Save robwilkerson/1258957 to your computer and use it in GitHub Desktop.
Attempts to intelligently use "a" and "an" in a sentence.
$l = array( 'a apple is a fruit', 'a banana is also a fruit' );
foreach( $l as $s ) {
$s = preg_replace( '/(^| )a ([aeiouAEIOU])/', '$1an $2', $s );
echo $s . "\n";
}
# outputs
an apple is a fruit
a banana is also a fruit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment