I run this php code:
echo "<br>system locales: ".system('locale -a')."<br><br>";
echo "current locales: ".setlocale(LC_ALL, 0)."<br><br>";
var_dump(setlocale (LC_ALL, 'de_DE.utf8'));
echo "current locales: ".setlocale(LC_ALL, 0)."<br><br>";
echo "accepting german characters?: ".ctype_alpha("äüöß")."<br><br>";
echo "accepting characters in general?: ".ctype_alpha("test")."<br><br>";
echo "rejecting numbers?: ".ctype_alpha("tes2t")."<br><br>";
and get this output:
C C.UTF-8 POSIX de_DE.utf8
system locales: de_DE.utf8
current locales: C
string(10) "de_DE.utf8" current locales: de_DE.utf8
accepting german characters?:
accepting characters in general?: 1
rejecting numbers?
I expected that after the call to setlocale (LC_ALL, 'de_DE.utf8') ctype_alpha would accept german characters like äöüß, as written in the documentation: "Returns TRUE if every character in text is a letter from the current locale, FALSE otherwise." but it doesn't. What am i doing wrong here?
PHP Version is : 5.3.10-1ubuntu3.8
It's not documented but, since you are using
utf8
version of the locale, if your file encoding is also UTF-8 you'll have to useutf8_decode()
to make it work:Tested with PHP 5.4.17-cli on a OS X Mavericks machine with UTF-8, ISO-8859-1, KOI8-U and Windows 1252 file encodings.