note 32057 deleted from function.ucfirst by nlopess

From: Date: Tue, 02 Mar 2004 15:29:28 +0000
Subject: note 32057 deleted from function.ucfirst by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-66113@lists.php.net to get a copy of this message
Note Submitter: dave@power2change.com ---- Try this cool sentence capitalization script that uses regular expressions. Note that it can't handle proper nouns. $val = ucfirst(strtolower($val)); // make the whole line lower case and capitalize the first word while (ereg("([a-z]+)(\.|\?|;|:|!)([ \"']+)([a-z])",$val,$regs)) // use this regular expression to find the beginning of a sentence. { $capword = ucfirst($regs[4]); // capitalize the word found $replacethis = $regs[1] . $regs[2] . $regs[3] . $regs[4]; $withthis = $regs[1] . $regs[2] . $regs[3] . $capword; $val = ereg_replace($replacethis,$withthis,$val); } print $val;

« previous php.notes (#66113) next »