Monday, September 21, 2009

php sentence to camel case


function sentenceToCamelCase($sentence)
{
$sentence = str_replace('a', '', $sentence);
$w = explode(" ", $sentence);
$ret='';
foreach($w as $i)
{
//echo $i;
$ret.=uppercaseWord($i);
}

return $ret;
}

function uppercaseWord($word)
{
return strtoupper(substr($word, 0,1)).substr($word, 1);
}

2 comments:

  1. // shorter one
    function camelcase($str) { return str_replace(' ', '', ucwords($str)); }

    ReplyDelete