note 33152 added to function.ucfirst

From: Date: Tue, 17 Jun 2003 20:10:17 +0000
Subject: note 33152 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-50530@lists.php.net to get a copy of this message
Couldn't find a good function to fix uppercase paragraphs (caps lock stuck??) for a message board project ... this works pretty well. (tested) echo FixTextCase("SHOUTING TEXT.ONEWORD? NEXT SENTENCE... BLA."); // produces "Shouting text. Oneword? Next sentence... Bla." function FixTextCase($text) { $text = strtolower($text); $sentences = preg_split("/(\.(\s)?|\?(\s)?)/",$text, -1,PREG_SPLIT_DELIM_CAPTURE); foreach($sentences as $x) { if ((trim($x) == ".") || (trim($x) == "?")) { $outtext .= trim($x)." "; } else { $outtext .= ucfirst(trim($x)); } } // fix double mark errors $outtext = preg_replace("/(\s\.)/",".",$outtext); $outtext = preg_replace("/(\s\?)/","?",$outtext); return $outtext; } (make sure the preg_split function is all on one line ...) ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33152 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33152&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33152&report=yes

« previous php.notes (#50530) next »