Forum Moderators: coopster

Message Too Old, No Replies

Make Camel Case

Goes along Google Search News thread

         

henry0

12:58 pm on May 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the thread [webmasterworld.com]

I wrote a short function to create your own Camel Case

<?php
// transform any number of words and spaces
// in a Camel Case string (useful for URL for example)

$str= "make camel case url";

function MakeCamelCase($str)
{
$upper=ucwords($str);
$str=str_replace(' ', '', $upper);

return $str;
}
$str=MakeCamelCase($str);
echo"new str $str";

?>

Have fun!

jatar_k

1:16 pm on May 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



don't encourage them henry0 ;)

pageoneresults

1:24 pm on May 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hey, leave henry0 alone!

Isn't camelCasing different than PascalCasing?

henry0

1:25 pm on May 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



as per the thread it's not that bad

I starder to write a foreach
Then I realized that it was not needed!
anyway it's just a fun exercise :)

coopster

8:00 pm on May 20, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Isn't camelCasing different than PascalCasing?

According to Wikipedia [en.wikipedia.org]:

Some people and organizations use the term camelCase only for lowerCamelCase, and refer to UpperCamelCase as PascalCase. In some contexts, however, the term CamelCase does not discriminate between the two.

The first two references give some insight. Here nor there, henry0's example would be UpperCamelCase, or PascalCase. I've taken the liberty to offer a lowerCamelCase function to add to the arsenal :)

function makeLowerCamelCase($str) 
{
return preg_replace("/\s+([a-z])/ie", 'strtoupper("$1")', trim($str));
}

Oh, BTW, there was a discussion in the JS Forum [webmasterworld.com] recently if you want to get the words back in a comma-separated list.