note 109744 deleted from function.ucfirst by danbrown

From: Date: Fri, 31 Aug 2012 15:57:07 +0000
Subject: note 109744 deleted from function.ucfirst by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190354@lists.php.net to get a copy of this message
Note Submitter: g dot kuizinas at anuary dot com ---- This is a better alternative to the previously suggested approaches. <?php if(!function_exists('mb_ucfirst')) { function mb_ucfirst($str, $encoding = NULL) { if($encoding === NULL) { $encoding = mb_internal_encoding(); } return mb_substr(mb_strtoupper($str, $encoding), 0, 1, $encoding) . mb_substr($str, 1, mb_strlen($str)-1, $encoding); } } $test_cases = array('test', 'šuo', 'äh', 'été indien'); header('Content-Type: text/plain'); foreach($test_cases as $tc) { echo mb_ucfirst($tc) . PHP_EOL; } ?> Test output: Test Šuo Äh Été indien

« previous php.notes (#190354) next »