PHP capitalize after dash

后端 未结 9 1659
长情又很酷
长情又很酷 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条回答
  •  Happy的楠姐
    2021-01-17 14:45

    look

    function UpperCaseAfterDash($wyraz)
      {
         $rozbij = explode('-',$wyraz);
         echo $rozbij[0].'-'.
         ucfirst($rozbij[1]);
      }
    
    UpperCaseAfterDash("input-text");
    

    Above function returns input-Text

    If you need only uppercase letter after one dash for example with city names (Jastrzębie-Zdrój) it will be enough, but if you need more than one... , just count how many array elements (after explode in above code) exists, then use loop.

    Greets,

提交回复
热议问题