It works if you set the locale correctly:
<?php
setLocale(LC_CTYPE, 'FR_fr.UTF-8');
?>
with this change you will get "yes" "yes"
ctype_alpha
(PHP 4 >= 4.0.4, PHP 5)
ctype_alpha — 英字かどうかを調べる
説明
bool ctype_alpha
( string $text
)
与えられた文字列 text のすべての文字が 英字であるかどうかを調べます。 標準の C ロケールの場合、文字は [A-Za-z] で、ctype_alpha() は $text が一文字のみの場合の (ctype_upper($text) || ctype_lower($text)) と等価です。 しかし、他の言語には大文字でも小文字でもない文字が含まれています。
パラメータ
- text
-
調べる文字列。
返り値
text のすべての文字が英字だった場合に TRUE 、そうでない場合に FALSE を返します。
例
例1 ctype_alpha()の例 (デフォルトのロケールを使用)
<?php
$strings = array('KjgWZC', 'arf12');
foreach ($strings as $testcase) {
if (ctype_alpha($testcase)) {
echo "文字列 $testcase は全て文字からなります。\n";
} else {
echo "文字列 $testcase は全てが文字から構成されているわけではありません。\n";
}
}
?>
上の例の出力は以下となります。
文字列 KjqWZC は全て文字からなります。 文字列 arf12 は全てが文字から構成されているわけではありません。
ctype_alpha
Tyrunur
27-May-2009 09:12
27-May-2009 09:12
jerome at yazo dot net
15-Mar-2009 04:18
15-Mar-2009 04:18
worth noticing? It seems that the ctype_alpha family of functions won't handle UTF-8 string (php 5.2.6)
<?php
$texte = 'jérôme';
setLocale(LC_CTYPE, 'FR_fr');
echo 'Pure ascii ? ', (ctype_alpha($texte) ) ? 'yes' : 'no';
echo '<br />';
$texte = iconv( "UTF-8", "ISO-8859-1", $texte) ;
echo 'Letters only ? ' , (ctype_alpha($texte) ) ? 'yes' : 'no';
?>
ouputs :
Pure ascii ? no
Letters only ? yes
