Converting the first letter of a string to a capital
Posted: Fri Dec 29, 2006 10:26 am
I'm sure I'm going to be needing
But at the moment my code is removing the first letter from each word and capitalising the rest of the word. Here's the code:
But this is my unwanted output:
Code: Select all
strtoupper & substrCode: Select all
$string = "this is the string i want to capitalise the first letter of each word on";
function upper($string) {
$storage = array();
$words = explode(" ", $string);
foreach ($words as $test) {
$storage[] = strtoupper(substr($test, 1));
}
print_r($storage);
}
upper($string);Any pointers please?Array
(
[0] => HIS
[1] => S
[2] => HE
[3] => TRING
[4] =>
[5] => ANT
[6] => O
[7] => APITALISE
[8] => HE
[9] => IRST
[10] => ETTER
[11] => F
[12] => ACH
[13] => ORD
[14] => N
)