I am trying to capitalise every word in a php string but the function isn't detecting a word that is being immediately followed by a bracket. How can I make it so that a word directly after a bracket is capitalised?
Example: amharic (ethiopian) .... Amharic (Ethiopian)
(currently using ucwords(), PHP displays Amharic (ethiopian) )
This is a known bug which requires there to be whitespace between open-parenthesis and the first letter. Here's a workaround:
$var = "amharic (ethiopian)";
echo str_replace('( ', '(', ucwords(str_replace('(', '( ', $var)));
Result
Amharic (Ethiopian)
See the demo
Try this,i tried it ,
$text= "amharic (ethiopian)";
echo mb_convert_case($text, MB_CASE_TITLE, "UTF-8");
output : Amharic (Ethiopian)
Note:It looks like the mbstring function on PHP is to be enabled.
Below function use to covert word with Bracket into Capitalize after Bracket
function ucWordWithBracket($edit){
$new_word = str_replace("(","( ",$edit);
$temp = ucwords($new_word);
$new_word = str_replace("( ","(",$temp);
return $new_word;
}
ucWordWithBracket(amharic (ethiopian))
Output of funcation is "Amharic (Ethiopian)";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With