note 102939 modified in function.strtoupper by danbrown
| From: | danbrown@php.net | Date: | Tue, 15 Mar 2011 16:17:49 +0000 |
| Subject: | note 102939 modified in function.strtoupper by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177912@lists.php.net to get a copy of this message | ||
For beginners: here is the most simple Camelize function for PHP. It converts underscore or dash
separated strings to camelCase, optionally with a Parameter to convert them to PascalCase (often
needed for Class names).
<?php
function camelize($string, $pascalCase = false)
{
$string = str_replace(array('-', '_'), ' ', $string);
$string = ucwords($string);
$string = str_replace(' ', '', $string);
if (!$pascalCase) {
return lcfirst($string);
}
return $string;
}
?>
--was--
For beginners: here is the most simple Camelize function for PHP. It converts underscore or dash
separated strings to camelCase, optionally with a Parameter to convert them to PascalCase (often
needed for Class names).
<?php
function camelize($string, $pascalCase = false)
{
$string = str_replace(array('-', '_'), ' ', $string);
$string = ucwords($string);
$string = str_replace(' ', '', $string);
if (!$pascalCase) {
return lcfirst($string);
}
return $string;
}
http://php.net/manual/en/function.strtoupper.php