note 108856 added to function.ucfirst

From: Date: Wed, 30 May 2012 18:15:05 +0000
Subject: note 108856 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-188302@lists.php.net to get a copy of this message
This function is multilanguage. It converts only the first character of the string to uppercase (UTF-8). Other chars in string will be unchanged. Usage: my_ucfirst("šlepetės ABC 123 abc"); // Returns Šlepetės ABC 123 abc function substr_unicode($str, $s, $l = null) { return join("", array_slice( preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), $s, $l)); } function my_ucfirst($string, $e ='utf-8') { $orig_string = $string; if (function_exists('mb_strtoupper') && function_exists('mb_substr') && !empty($string)) { $string = mb_strtolower($string, $e); $upper = mb_strtoupper($string, $e); preg_match('#(.)#us', $upper, $matches); $string = $matches[1] . mb_substr($string, 1, mb_strlen($string, $e), $e); } else { $string = ucfirst($string); } $string1 = substr_unicode($string, 0, 1); $string2 = substr_unicode($orig_string, 1); $string = $string1 . $string2; return $string; } ---- Server IP: 69.147.83.197 Probable Submitter: 78.56.134.21 ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- https://master.php.net/note/edit/108856 Del: integrated -- https://master.php.net/note/delete/108856/integrated Del: useless -- https://master.php.net/note/delete/108856/useless Del: bad code -- https://master.php.net/note/delete/108856/bad+code Del: spam -- https://master.php.net/note/delete/108856/spam Del: non-english -- https://master.php.net/note/delete/108856/non-english Del: in docs -- https://master.php.net/note/delete/108856/in+docs Del: other reasons-- https://master.php.net/note/delete/108856 Reject -- https://master.php.net/note/reject/108856 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188302) next »