PHP capitalize after dash

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

    It is important to note that the solutions provided here will not work with UTF-8 strings!

    $str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει-υπέρ νωθρού κυνός";
    $str = explode('-', mb_convert_case( $str, MB_CASE_TITLE ) );
    $str = implode('-', array_map('mb_convert_case', $str, array(MB_CASE_TITLE, "UTF-8")) );
    echo $str;
    
    // str= Τάχιστη Αλώπηξ Βαφήσ Ψημένη Γη, Δρασκελίζει-Υπέρ Νωθρού Κυνόσ
    

提交回复
热议问题