note 106737 modified in function.mb-substr by danbrown

From: Date: Fri, 02 Dec 2011 22:24:47 +0000
Subject: note 106737 modified in function.mb-substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184875@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: <?php 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! --was-- 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! http://php.net/manual/en/function.mb-substr.php

« previous php.notes (#184875) next »