note 86459 modified in function.ucwords by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Oct 2008 14:20:30 +0000 |
| Subject: | note 86459 modified in function.ucwords by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145514@lists.php.net to get a copy of this message | ||
I have looked for a work-around that would upper-case letter after an ' too.
For example,
ucword("o'lunney's");
would output "O'lunney's" and I wanted it to output
"O'Lunney's".
Here is my function:
<?php
function my_ucwords($string) {
$string = ucwords(strtolower($string));
$string = preg_replace_callback("/( [
a-zA-Z]{1}')([a-zA-Z0-9]{1})/s",create_function('$matches','return
$matches[1].strtoupper($matches[2]);'),$string);
return $string;
}
?>
Hope it helps someone.
--was--
I have looked for a work-around that would upper-case letter after an ' too.
For example,
ucword("o'lunney's");
would output "O'lunney's" and I wanted it to output
"O'Lunney's".
Here is my function:
function my_ucwords($string) {
$string = ucwords(strtolower($string));
$string = preg_replace_callback("/( [
a-zA-Z]{1}')([a-zA-Z0-9]{1})/s",create_function('$matches','return
$matches[1].strtoupper($matches[2]);'),$string);
return $string;
}
Hope it helps someone.
http://php.net/manual/en/function.ucwords.php