note 51137 added to function.ucwords
| From: | j dot ravier at free dot fr | Date: | Mon, 21 Mar 2005 12:50:02 +0000 |
| Subject: | note 51137 added to function.ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86741@lists.php.net to get a copy of this message | ||
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).
----
Manual Page -- http://www.php.net/manual/en/function.ucwords.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51137
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51137&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51137&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51137&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51137&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51137&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51137&report=yes
Search -- http://master.php.net/manage/user-notes.php