Underscore To Camel Case
Sometimes in life we are presented with strings containing underscores. If you need such a string in camelCase, this function will get you on your way.
USAGE
DEMONSTRATION
ThisIsUnderScoreWord
<?php
/**
* Convert strings with underscores into CamelCase
*
* @param string $string The string to convert
* @param bool $first_char_caps camelCase or CamelCase
* @return string The converted string
*
*/function underscoreToCamelCase( $string, $first_char_caps = false)
{
if( $first_char_caps == true )
{
$string[0] = strtoupper($string[0]);
}
$func = create_function('$c', 'return strtoupper($c[1]);');
return preg_replace_callback('/_([a-z])/', $func, $string);
}
?>
<?php
$str = 'this_is_under_score_word';
echo underscoreToCamelCase( $str, 1 );?>
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment