Created
September 19, 2012 02:38
-
-
Save CodeNegar/3747334 to your computer and use it in GitHub Desktop.
PHP: camel Case Get Parts
This file contains hidden or 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 up($str){ | |
return strtoupper($str); | |
} | |
function camelCaseGetParts($str, $count=0) | |
{ | |
$parts = array() ; | |
$partIndex = 1 ; | |
$len = strlen($str) ; | |
for($i=0;$i<$len;$i++) | |
{ | |
$char = $str[$i]; | |
if ($char===up($char))$partIndex++; | |
if($partIndex-1 == $count-1 && $count != 0) | |
{ | |
$parts[$partIndex-1] = substr($str,$i,len($str)); | |
return $parts; | |
} | |
$parts[$partIndex-1] .= $char; | |
} | |
return $parts; | |
} | |
print_r(camelCaseGetParts("camelCaseGetParts")); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment