note 90195 deleted from function.mb-convert-case by danbrown

From: Date: Thu, 09 Apr 2009 15:03:26 +0000
Subject: note 90195 deleted from function.mb-convert-case by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153021@lists.php.net to get a copy of this message
Note Submitter: the at psychoticneurotic dot com ---- Oops.. should have proof read my code. It should read: <?php function titleCase($string, $delimiters = array(" ", "-", "O'"), $exceptions = array("to", "a", "the", "of", "by", "and", "with", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X")) { /* * Exceptions in lower case are words you don't want converted * Exceptions all in upper case are any words you don't want converted to title case * but should be converted to upper case, e.g.: * king henry viii or king henry Viii should be King Henry VIII */ foreach ($delimiters as $delimiter){ $words = explode($delimiter, $string); $newwords = array(); foreach ($words as $word){ if (in_array(strtoupper($word), $exceptions)){ // check exceptions list for any words that should be in upper case $word = strtoupper($word); } elseif (!in_array($word, $exceptions)){ // convert to uppercase $word = ucfirst($word); } array_push($newwords, $word); } $string = join($delimiter, $newwords); } return $string; } ?>

« previous php.notes (#153021) next »