note 93763 modified in function.ucfirst by danbrown

From: Date: Sun, 27 Sep 2009 01:27:56 +0000
Subject: note 93763 modified in function.ucfirst by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161104@lists.php.net to get a copy of this message
For lithuanian text with utf-8 encoding I use two functions (thanks [mattalexxpub at gmail dot com] and Svetoslav Marinov) <?php function my_ucfirst($string, $e ='utf-8') { 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); } return $string; } function sentence_case($string) { $sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); $new_string = ''; foreach ($sentences as $key => $sentence) { $new_string .= ($key & 1) == 0? my_ucfirst(strtolower(trim($sentence))) : $sentence.' '; } return trim($new_string); } ?> --was-- For lithuanian text with utf-8 encoding I use two functions (thanks „mattalexxpub at gmail dot com“ and Svetoslav Marinov) function my_ucfirst($string, $e ='utf-8') { 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); } return $string; } function sentence_case($string) { $sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); $new_string = ''; foreach ($sentences as $key => $sentence) { $new_string .= ($key & 1) == 0? my_ucfirst(strtolower(trim($sentence))) : $sentence.' '; } return trim($new_string); } http://php.net/manual/en/function.ucfirst.php

« previous php.notes (#161104) next »