If I bring sexy back, do I need a receipt?


I needed the first letter of every word in any given string to be capitalized. So I wrote a small little function to parse the string and create an array with all the words. I then loop through the array, break off the first letter, capitalize it and reattach it. We finally join the string with the other words and trim extra space at the end.

This function performs well and gets the job done.

function CapitalizeText($text){
$text = explode(" ", $text);
foreach($text as $t){
$CapText .= strtoupper($t{0}) . substr($t,1) . " ";
}
$CapText = trim($CapText);
return $CapText;
}

I started to think that someone else has to have done this (that never matters to me, I like writing my own stuff) and I searched to see if I was right. It turns out PHP (both 4 and 5) have this…built in.

All you need to type is ucwords($string) and it does the exact same thing as my function. Oh well, it is ALWAYS better to use built in functions. So goodbye, CapatilizeText(). Why didn't you tell me you are "moo like a cows opinion?"

Tags:

Leave a Reply

WDP Wall

Latest on November 24, 2008

Slim: Damn, if that is Sharae it's a good thing you didn't call her back.....but ...what if that wasn't.....

IceburgTX: http://www.jonathancoulton.com/mp3/Code%20Monkey.mp3. There's your theme song, J.

IceburgTX: God made dirt and dirt bust yo' ass!

unknown: Sharae sound like a sexy vixen.... Did you ever call her?

JM: Yeee-aaaah booo-eee. Go Lakers!

space roach: 3 down, 79 to go

phuker#1: the most dominate team to ever play in the NBA

Deez...: ...Nuts.

phuker#1: Where's them taggers @?

IceburgTX: "I felt like destroying something beautiful."

» Graffiti The Wall



RSS Facebook Status

Archives

Tags

Blogroll

RSS Reddit

RSS Hollywood Tuna

RSS Digg

RSS Stereogum

RSS Egotastic

Spam Blocked