note 44209 deleted from function.preg-match by tomsommer

From: Date: Sun, 18 Jul 2004 13:24:13 +0000
Subject: note 44209 deleted from function.preg-match by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73481@lists.php.net to get a copy of this message
Note Submitter: fungineer@gmail.com ---- [Editor's note: When adding the i Pattern Modifier, you can also test on lowercase words. This means you won't need to have everything in sentence case/upper case at start] Testing for indefinite articles in the English Language. As I'm new to PHP and Regex, I decided to practice on something that would make my pages more sophisticated. When choosing from a drop-down menu of models of cars (e.g. Civic, CR-V, Accord etc.) I wanted to then be able to output: "Joe drives a Civic." or "Mary drives an Accord." The difference is the way "a" & "an" are used in English. This simple group of functions helped me grab the first letter, test if it was a vowel and then choose the proper article. <?php $first_letter = substr($value, 0, 1); // $value is the string you're grabbing the first letter from if(preg_match("/^A|E|I|O|U/", $first_letter)) { $article = "an"; } else { $article = "a"; } ?>

« previous php.notes (#73481) next »