note 81258 added to function.ucfirst

From: Date: Wed, 20 Feb 2008 11:48:10 +0000
Subject: note 81258 added to function.ucfirst
Groups: php.notes 
Request: Send a blank email to php-notes+get-136309@lists.php.net to get a copy of this message
Here's a function to capitalize segments of a name, and put the rest into lower case. You can pass the characters you want to use as delimiters. i.e. <?php echo nameize("john o'grady-smith"); ?> returns John O'Grady-Smith <?php function nameize($str,$a_char = array("'","-"," ")){ //$str contains the complete raw name string //$a_char is an array containing the characters we use as separators for capitalization. If you don't pass anything, there are three in there as default. $string = strtolower($str); foreach ($a_char as $temp){ $pos = strpos($string,$temp); if ($pos){ //we are in the loop because we found one of the special characters in the array, so lets split it up into chunks and capitalize each one. $mend = ''; $a_split = explode($temp,$string); foreach ($a_split as $temp2){ //capitalize each portion of the string which was separated at a special character $mend .= ucfirst($temp2).$temp; } $string = substr($mend,0,-1); } } return ucfirst($string); } ?> ---- Server IP: 92.48.74.199 Probable Submitter: 81.171.161.19 ---- Manual Page -- http://www.php.net/manual/en/function.ucfirst.php Edit -- https://master.php.net/note/edit/81258 Del: integrated -- https://master.php.net/note/delete/81258/integrated Del: useless -- https://master.php.net/note/delete/81258/useless Del: bad code -- https://master.php.net/note/delete/81258/bad+code Del: spam -- https://master.php.net/note/delete/81258/spam Del: non-english -- https://master.php.net/note/delete/81258/non-english Del: in docs -- https://master.php.net/note/delete/81258/in+docs Del: other reasons-- https://master.php.net/note/delete/81258 Reject -- https://master.php.net/note/reject/81258 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136309) next »