How to uppercase first letter after a hyphen, ie Adam Smith-Jones

前端 未结 9 1463
野趣味
野趣味 2021-02-01 22:30

I\'m looking for a way to uppercase the first letter/s of a string, including where the names are joined by a hyphen, such as adam smith-jones needs to be Adam Smith-Jones.

9条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 23:24

    function capWords($string) {
        $string = str_replace("-", " - ", $string);
        $string = ucwords(strtolower($string));
        $string = str_replace(" - ", "-", $string);
    
        return $string;
    }
    

提交回复
热议问题