note 79228 deleted from function.ucwords by felipe

From: Date: Mon, 24 Dec 2007 02:26:28 +0000
Subject: note 79228 deleted from function.ucwords by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133951@lists.php.net to get a copy of this message
Note Submitter: bcordingley at metroland dot com ---- This function will return the first word of a str in title case. TITLE CASE PHP FUNCTION how to turn first word into TITLE CASE Hope it helps Barry Cordingley yourclassifieds.ca || metroland.com function titleCase($string, $num) { $rtnStn = array(); $str = explode(" ", $string); foreach ($str as $key =>$v){ switch ($key){ case ($key !== '0'); $rtnStn[] = $v; break; }} $rtnStn = implode(' ', $rtnStn); $wrds = str_word_count($string, 2); $rst = array(); $fstWrds = array_slice( $wrds, 0, $num); $str = implode(' ', $fstWrds); $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY); $ucase = array(); foreach ($chars as $key =>$v){ $ucase[] = ucfirst($v); } return ''.implode('', $ucase).' '.$rtnStn.''; }

« previous php.notes (#133951) next »