PHP capitalize after dash

后端 未结 9 1666
长情又很酷
长情又很酷 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:30

    You could do it with a regular expression callback method like this:

    $q = preg_replace_callback('/\-([a-z]+)/g', create_function(
                '$m', 'return "-" . ucfirst($m[1]);'
            ),$q)
    

提交回复
热议问题