note 105687 deleted from function.ctype-alnum by danbrown
| From: | danbrown@php.net | Date: | Wed, 07 Sep 2011 15:40:03 +0000 |
| Subject: | note 105687 deleted from function.ctype-alnum by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183008@lists.php.net to get a copy of this message | ||
Note Submitter: daniel dot rhodes at warpasylum dot co dot uk
----
I'm using PHP 5.3.5 and, for me at least, there seems to be an important caveat with this
function. The current system locale *is* being honoured, but Unicode (or at least UTF-8) is not
giving the expected results. Thus:
<?php
//note script file itself its UTF-8
$utf8_string = 'jérômecaractèresdelachaîne';
$iso_string = iconv('UTF-8', 'ISO-8859-1', $utf8_string);
//or:
//$iso_string = mb_convert_encoding($utf8_string, 'ISO-8859-1', 'UTF-8');
setlocale(LC_ALL, 'fr_FR.utf8');
var_dump(nl_langinfo(CODESET)); //gives UTF-8
var_dump(ctype_alnum($utf8_string)); //gives FALSE
setlocale(LC_ALL, 'fr_FR');
var_dump(nl_langinfo(CODESET)); //gives ISO-8859-1
var_dump(ctype_alnum($iso_string)); //gives TRUE
?>