note 51137 deleted from function.ucwords by derick
| From: | derick@php.net | Date: | Tue, 30 Aug 2005 11:18:19 +0000 |
| Subject: | note 51137 deleted from function.ucwords by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94398@lists.php.net to get a copy of this message | ||
Note Submitter: j dot ravier at free dot fr
----
For western accentuated letters:
You can use a simple preg_replace expression to replace ucwords if you have only the ascii
characters converted.
<?php
function ucwordsw($value) {
return preg_replace('/(^|[^A-Za-z0-9_\xC0-\xFF])([a-z\xE0-\xFF])/e',
'"$1".chr(ord("$2")-32)', $value);
}
?>
- Redefinition of '\w' (a word character) : [A-Za-z0-9_\xC0-\xFF]
includes the western accentuated letters, lower or upper case.
- Redefinition of '\W' (a non word character) :
^|[^A-Za-z0-9_\xC0-\xFF]
-> either the beginning (^) of the searched string or any non ([^...]} newly defined
'word' character
So any lower case letter ($2),
- accentuated ([\xE0-\xFF]) or not ([a-z]),
- and following a non word character ($1)
will be uppercased (chr(ord('...')-32)
(took that bit from a post from Ansis [ataols in latnet point lv] (27-Jan-2004 11:40) on the
strtoupper function page http://www.php.net/manual/fr/function.strtoupper.php).