Skip to content

Instantly share code, notes, and snippets.

@CodeNegar
Created September 19, 2012 02:38
Show Gist options
  • Save CodeNegar/3747334 to your computer and use it in GitHub Desktop.
Save CodeNegar/3747334 to your computer and use it in GitHub Desktop.
PHP: camel Case Get Parts
<?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