note 86902 added to function.ucfirst

From: Date: Mon, 10 Nov 2008 01:10:45 +0000
Subject: note 86902 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-146331@lists.php.net to get a copy of this message
This is what I use for converting strings to sentence case: 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? ucfirst(strtolower(trim($sentence))) : $sentence.' '; } return trim($new_string); } print sentence_case('HMM. WOW! WHAT?'); // Outputs: "Hmm. Wow! What?" ---- Server IP: 208.69.120.35 Probable Submitter: 67.42.63.210 ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- https://master.php.net/note/edit/86902 Del: integrated -- https://master.php.net/note/delete/86902/integrated Del: useless -- https://master.php.net/note/delete/86902/useless Del: bad code -- https://master.php.net/note/delete/86902/bad+code Del: spam -- https://master.php.net/note/delete/86902/spam Del: non-english -- https://master.php.net/note/delete/86902/non-english Del: in docs -- https://master.php.net/note/delete/86902/in+docs Del: other reasons-- https://master.php.net/note/delete/86902 Reject -- https://master.php.net/note/reject/86902 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146331) next »