note 32057 added to function.ucfirst
| From: | dave at power2change dot com | Date: | Wed, 14 May 2003 22:51:57 +0000 |
| Subject: | note 32057 added to function.ucfirst | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47996@lists.php.net to get a copy of this message | ||
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;
--
http://www.php.net/manual/en/function.ucfirst.php
http://master.php.net/manage/user-notes.php?action=edit+32057
http://master.php.net/manage/user-notes.php?action=delete+32057
http://master.php.net/manage/user-notes.php?action=reject+32057