I have texts in UTF-8 with diacritic characters also, and would like to check if first letter of this text is upper case or lower case. How to do this?
A:
Tried ?
$str = 'the text to test';
if($str{0} === strtoupper($str{0})) {
echo 'yepp, its uppercase';
}
else{
echo 'nope, its not upper case';
}
PHP_Jedi
2010-05-11 22:32:21
what does mean $str{0}? I don't know this notation...
tomaszs
2010-05-12 09:16:42
+4
A:
function starts_with_upper($str) {
$chr = mb_substr ($str, 0, 1, "UTF-8");
return mb_strtolower($chr, "UTF-8") != $chr;
}
Note that mb_substr is necessary to correctly isolate the first character.
Artefacto
2010-05-11 22:36:21
thank you, your answer is right. You can not use $str[0] on UTF-8 string.
tomaszs
2010-05-11 22:53:44
Doesn't always work. There are Unicode characters that are capital letters (i.e., category Lu) but don't have a lowercase mapping. Mostly, the mathematical bold/italic/double-struck letters.
dan04
2010-05-13 06:25:52
Artefacto
2010-05-13 07:17:53