【问题标题】:How to make the second character uppercase?如何使第二个字符大写?
【发布时间】:2016-03-03 17:02:02
【问题描述】:

我经常使用 Apple 产品名称

"iphone"
"ipad"
"imac"

将第二个字符变为大写的最快方法是什么?

"iPhone"
"iPad"
"iMac"

我试过了

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

【问题讨论】:

标签: php substring offset uppercase


【解决方案1】:

您必须替换原始变量中的值:

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

【讨论】:

    【解决方案2】:

    完美答案

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

    【讨论】:

    • 这并不能解释您更改了什么或它是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 2022-11-06
    • 2020-01-10
    • 1970-01-01
    • 2011-01-26
    • 2011-08-18
    • 2022-01-09
    • 1970-01-01
    相关资源
    最近更新 更多