PHP: change "a" to "an" before vowel [was: How do I code this?]
I have this nice little cookie: <?php echo $_COOKIE['targ_lang']; ?> . It inserts language names, like Portuguese or French into the text.
Mostly, in the text that preceeds the cookie I use the indefinite article, 'a', 'cookie', followed by something like 'newspaper'.
The code reads as: a <?php echo $_COOKIE['targ_lang']; ?> newspaper
and it renders as: "...a Portuguese newspaper."
But sometimes the nationality starts with a vowel and that messes up the grammar of the phrase, i.e.: "...a Arabic newspaper." ick
I want a snippet that will insert an 'n' after the 'a' so it will read: "...an Arabic newspaper."
So how do I write that?
$A = A;
$E=E;
$I=I;
$O=O;
$U=U;
(I'm not worried about Yagurkistan)
<?php if $_COOKIE['targ_lang']; ?> begins with $A OR $E OR $I OR $O OR $U; echo ‘n’; ?>
I assume I assign variables to the letters A,E,I,O,U and slip this in after the 'a'. But what is the code for 'begins with'.
I'm sure glad you guys and gals are here to help and thank you!
Brian
[Subject amended by moderator to make it more meaningful]
