PHP capitalize after dash

后端 未结 9 1603
长情又很酷
长情又很酷 2021-01-17 13:46
$q = durham-region;

$q = ucfirst($q);

$q = Durham-region;

How would I capitalize the letter after the dash (Durham-Region)? Would I have to spli

9条回答
  •  旧巷少年郎
    2021-01-17 14:46

    Yes. ucfirst() simply capitalized the first letter of the string. If you want multiple letters capitalized, you must create multiple strings.

    $strings = explode("-", $string);
    $newString = "";
    foreach($strings as $string){
        $newString += ucfirst($string);
    }
    
    function ucfirst_all($delimiter, $string){
        $strings = explode("-", $string);
        $newString = "";
        foreach($strings as $string){
            $newString += ucfirst($string);
        }
        return $newString;
    }
    

提交回复
热议问题