Should I be using mb_convert_case
with MB_CASE_TITLE
or ucwords
? Or something else? What will the differences be?
Asked
Active
Viewed 1,022 times
4

RobertPitt
- 56,863
- 21
- 114
- 161

Ben G
- 26,091
- 34
- 103
- 170
-
which language are you talking about? – Programmer Dec 24 '10 at 19:56
2 Answers
3
It depends.
mb_convert_case()
is multibyte safe. ucwords()
is not.
mb_convert_case()
requires an extension that is not always available. ucwords()
is always available.
So if your application will only ever use single-byte encodings then ucwords()
gives you better portability.
But if your application might need to process multi-byte encodings then ucwords()
will fail you.
1
function uc_words($string){
return mb_convert_case($string, MB_CASE_TITLE, "UTF-8");
}
MB means multi byte, so it can convert non-ASCII characters, ucwords can convert only ASCII.
If you use ucwords on "moj šal", you will get "Moj šal", if you use multi byte convert you will get "Moj Šal"... that's it.

Dejan Marjanović
- 19,244
- 7
- 52
- 66
-
-
mb_convert_case, it is using it, this is just a function so he can choose upper, lower, or title case conversion. As I stated it works with UTF-8 (multibyte) while ucwords only works with ASCII. – Dejan Marjanović Dec 24 '10 at 20:32
-
babonk can choose upper, lower, or title case conversion perfectly easily using `mb_convert_case()` directly. What additional functionality does your `mb_convert()` function offer? I can't see any. It's just overhead. – Dec 24 '10 at 20:35
-
Absolutely nothing, I edited my post, he can write a function that will work with multibyte encodings. I always use something like this. – Dejan Marjanović Dec 24 '10 at 20:47
-