Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php capitalise word after bracket

Tags:

php

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) )

like image 643
Jake Avatar asked Mar 29 '13 01:03

Jake


3 Answers

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

like image 189
Kermit Avatar answered Nov 20 '22 10:11

Kermit


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.

like image 41
internals-in Avatar answered Nov 20 '22 09:11

internals-in


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)";

like image 1
Naitik Shah Avatar answered Nov 20 '22 10:11

Naitik Shah