note 106737 added to function.mb-substr
| From: | p dot assenov at aip-solutions dot com | Date: | Fri, 02 Dec 2011 17:17:20 +0000 |
| Subject: | note 106737 added to function.mb-substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184861@lists.php.net to get a copy of this message | ||
I'm trying to capitalize only the first character of the string and tried some of the examples
above but they didn't work. It seems mb_substr() cannot calculate the length of the string in
multi-byte encoding (UTF-8) and it should be set explicitly. Here is the corrected version:
function mb_ucfirst($str, $enc = 'utf-8') {
return mb_strtoupper(mb_substr($str, 0, 1, $enc), $enc).mb_substr($str, 1, mb_strlen($str, $enc),
$enc);
}
cheers!
----
Server IP: 217.75.128.29
Probable Submitter: 78.90.210.92
----
Manual Page -- http://www.php.net/manual/en/function.mb-substr.php
Edit -- https://master.php.net/note/edit/106737
Del: integrated -- https://master.php.net/note/delete/106737/integrated
Del: useless -- https://master.php.net/note/delete/106737/useless
Del: bad code -- https://master.php.net/note/delete/106737/bad+code
Del: spam -- https://master.php.net/note/delete/106737/spam
Del: non-english -- https://master.php.net/note/delete/106737/non-english
Del: in docs -- https://master.php.net/note/delete/106737/in+docs
Del: other reasons-- https://master.php.net/note/delete/106737
Reject -- https://master.php.net/note/reject/106737
Search -- https://master.php.net/manage/user-notes.php