ucwords function with exceptions

前端 未结 5 2245
你的背包
你的背包 2020-12-17 05:47

I need some help i have this code that Uppercase the first character of each word in a string with exceptions i need the function to ignore the exception if it\'s at the beg

5条回答
  •  太阳男子
    2020-12-17 06:26

    what about you make the first letter in the string upper case so no matter your mix you will still come through

    $string = "my cat is going to the vet";
    $string = ucfirst($string);
    $ignore = array("is", "to", "the");
    echo ucwordss($string, $ignore);
    

    this way you first letter of the string will always be upper case

提交回复
热议问题