Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

need capitalize words with special chars in PHP

Tags:

php

capitalize

ucwords doesn't capitalize foreign chars like öüäõ

so I need a solution, which will make "öösel" into "Öösel"

Is there a simple way to do it with regexp or I have to check all the characters manually?

like image 932
Hannes Avatar asked Jan 04 '11 00:01

Hannes


2 Answers

If you have the mbstring extension installed, you can use the mb_convert_case function, specifying MB_CASE_TITLE as the $mode parameter.

like image 94
Dean Harding Avatar answered Nov 15 '22 00:11

Dean Harding


You can give a try to strtoupper() which works fine for me with French.
Sorry I hadn't seen it was ucwords...

Otherwise, this should work:

mb_convert_case($string, MB_CASE_TITLE, "UTF-8");

like image 33
Nabab Avatar answered Nov 14 '22 23:11

Nabab