note 12063 modified in function.ucwords by felipe
| From: | felipe@php.net | Date: | Tue, 22 Jul 2008 19:03:13 +0000 |
| Subject: | note 12063 modified in function.ucwords by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142543@lists.php.net to get a copy of this message | ||
The code posted above by Joerg Krause only works for a string which ends with one of the delimiters.
A possible fix is:
<?php
$text = "What?No delimiters,shit happens here.this solves all problems.";
preg_match_all("/(\w+[,. ?])+/U", $text, $words);
preg_match("/(\w+)$/", $text, $lastword);
$words[0][] = $lastword;
foreach($words[0] as $part) $uwords[] = ucfirst($part);
$text = implode("", $uwords);
echo $text;
?>
--was--
The code posted above by Joerg Krause only works for a string which ends with one of the delimiters.
A possible fix is:
$text = "What?No delimiters,shit happens here.this solves all problems.";
preg_match_all("/(\w+[,. ?])+/U", $text, $words);
preg_match("/(\w+)$/", $text, $lastword);
$words[0][] = $lastword;
foreach($words[0] as $part) $uwords[] = ucfirst($part);
$text = implode("", $uwords);
echo $text;
http://php.net/manual/en/function.ucwords.php