Created
September 27, 2010 11:41
-
-
Save yuya-takeyama/598895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function camelize($input, $lower = false) | |
{ | |
$result = ''; | |
$words = explode('_', $input); | |
$wordCount = count($words); | |
for ($i = 0; $i < $wordCount; $i++) { | |
$word = $words[$i]; | |
if (!($i === 0 && $lower === false)) { | |
$word = ucfirst($word); | |
} else { | |
$word = strtolower($word); | |
} | |
$result .= $word; | |
} | |
return $result; | |
} | |
$input = "camel_case_string"; | |
echo camelize($input) . PHP_EOL; // => CamelCaseString | |
echo camelize($input, true) . PHP_EOL; // => camelCaseString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment