note 81662 deleted from function.strtoupper by hholzgra

From: Date: Thu, 02 Aug 2012 13:07:38 +0000
Subject: note 81662 deleted from function.strtoupper by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189708@lists.php.net to get a copy of this message
Note Submitter: jesdisciple at gmail dot com ---- This function takes a space-delimited list of words and returns it as one camelcase word. <?php function strtocamel($str){ $str = explode(' ', strtolower($str)); for($i = 1; $i < count($str); $i++){ $str[$i] = strtoupper(substr($str[$i], 0, 1)) . substr($str[$i], 1); } return implode('', $str); } ?> Example: <?php echo strtocamel('Str tO CAMEL'); ?> This will output 'strToCamel'. To also make the first letter uppercase, change '$i = 1' to '$i = 0'.

« previous php.notes (#189708) next »