code-8
code-8

Reputation: 58662

How to make the second character uppercase?

I work with Apple Product Name a lot

"iphone"
"ipad"
"imac"

What would be the quickest way to make the second character uppercase?

"iPhone"
"iPad"
"iMac"

I tried

// $name = iphone
if ($name[0] == 'i') {
    strtoupper($name[1]);
    dd($name); //iphone
}

Upvotes: 2

Views: 1327

Answers (2)

Santosh Ram Kunjir
Santosh Ram Kunjir

Reputation: 1082

Perfect answer

 $word ='iphone';
 $result = str_replace(substr($word,1,1),ucfirst(substr($word,1,1)),$word);
 echo $result;

Upvotes: 2

Misa Lazovic
Misa Lazovic

Reputation: 2823

You have to replace the value in original variable:

$name[1] = strtoupper($name[1]);

Upvotes: 9

Related Questions