Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uppercase each words after space,dot,comma

I want to replace all words first character uppercase. I can do this with ucwords but its not unicode encoding. also i need to set delimiters.

this is the, sample text.for replace the each words in, this'text sample' words

I want this text convert to

This İs The, Sample Text.For Replace The Each Words İn, This'Text Sample' Words

After comma, after dot, after space, after comma(not space), after dot(not space)

How can i convert to upper characters with utf-8, Thanks.

https://eval.in/485321

like image 790
Kadir Çetintaş Avatar asked Mar 14 '23 21:03

Kadir Çetintaş


2 Answers

ucwords() is a built-in function for this specific problem. You have to set your own delimiters as its second argument:

echo ucwords(strtolower($string), '\',. ');

Outputs:

This Is The, Sample Text.For Replace The Each Words In, This'Text Sample' Words

like image 138
revo Avatar answered Mar 25 '23 11:03

revo


For this use mb_convert_case with second parameter MB_CASE_TITLE.

like image 42
u_mulder Avatar answered Mar 25 '23 10:03

u_mulder