note 79227 added to function.ucfirst

From: Date: Fri, 16 Nov 2007 05:46:18 +0000
Subject: note 79227 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-132339@lists.php.net to get a copy of this message
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.''; } ---- Server IP: 217.160.72.57 Probable Submitter: 72.39.164.172 ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- https://master.php.net/note/edit/79227 Del: integrated -- https://master.php.net/note/delete/79227/integrated Del: useless -- https://master.php.net/note/delete/79227/useless Del: bad code -- https://master.php.net/note/delete/79227/bad+code Del: spam -- https://master.php.net/note/delete/79227/spam Del: non-english -- https://master.php.net/note/delete/79227/non-english Del: in docs -- https://master.php.net/note/delete/79227/in+docs Del: other reasons-- https://master.php.net/note/delete/79227 Reject -- https://master.php.net/note/reject/79227 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132339) next »