note 10313 added to ucwords
| From: | joerg at krause dot net | Date: | Wed, 27 Dec 2000 15:06:56 +0000 |
| Subject: | note 10313 added to ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-9125@lists.php.net to get a copy of this message | ||
None of the examples above recognizes characters normally used as delimiters. The following uses a
regular expression, which is easy to extend, to create an array with the parts of a text. Then it
runs the ucfirst-function for each part an implode the array:
$text = "What?No delimiters,shit happens here.this solves all problems.";
preg_match_all("/(\w+[,. ?])+/U", $text, $words);
foreach($words[0] as $part) $uwords[] = ucfirst($part);
$text = implode("", $uwords);
echo $text;
Joerg Krause
www.php.comzept.de
www.joergkrause.de/krause
http://www.php.net/manual/function.ucwords.php