note 76384 added to function.ucfirst

From: Date: Thu, 12 Jul 2007 18:57:02 +0000
Subject: note 76384 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-128419@lists.php.net to get a copy of this message
Ken and zee One thing I would do to make this more unviersally work would be to add strtolower() around your $sentence. Doing this will allow you to convert an all caps text block as well as an all lowercase text block. <?php function sentence_cap($impexp, $sentence_split) { $textbad=explode($impexp, $sentence_split); $newtext = array(); foreach ($textbad as $sentence) { $sentencegood=ucfirst(strtolower($sentence)); $newtext[] = $sentencegood; } $textgood = implode($impexp, $newtext); return $textgood; } $text = "this is a sentence. this is another sentence! this is the fourth sentence? no, this is the fourth sentence."; $text = sentence_cap(". ",$text); $text = sentence_cap("! ",$text); $text = sentence_cap("? ",$text); echo $text; // This is a sentence. This is another sentence! This is the fourth sentence? No, this is the fourth sentence. ?> ---- Server IP: 208.69.120.35 Probable Submitter: 69.15.126.114 ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- https://master.php.net/note/edit/76384 Del: integrated -- https://master.php.net/note/delete/76384/integrated Del: useless -- https://master.php.net/note/delete/76384/useless Del: bad code -- https://master.php.net/note/delete/76384/bad+code Del: spam -- https://master.php.net/note/delete/76384/spam Del: non-english -- https://master.php.net/note/delete/76384/non-english Del: in docs -- https://master.php.net/note/delete/76384/in+docs Del: other reasons-- https://master.php.net/note/delete/76384 Reject -- https://master.php.net/note/reject/76384 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128419) next »