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 — Verifica se os caracteres são alfabéticos
Descrição
bool ctype_alpha
( string $text
)
Verifica se todos os caracteres na string fornecida, text , são alfabéticos. No padrão C locale letras são [A-Za-z] e ctype_alpha() é equivalente a (ctype_upper($text) || ctype_lower($text)) se $text é um único caractere, mas outras linguagens possuem letras que não são considerada nem maiúscula nem minúscula.
Parâmetros
- text
-
A string a ser testada.
Valor Retornado
Retorna TRUE se todos caracteres em text é uma letra do atual locale, FALSE caso contrário.
Exemplos
Exemplo #1 Um exemplo da ctype_alpha() (usando o locale padrão)
<?php
$strings = array('KjgWZC', 'arf12');
foreach ($strings as $testcase) {
if (ctype_alpha($testcase)) {
echo "The string $testcase consists of all letters.\n";
} else {
echo "The string $testcase does not consist of all letters.\n";
}
}
?>
O exemplo acima irá imprimir:
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.
Veja Também
- ctype_upper() - Verifica se os caracteres são maiúsculos
- ctype_lower() - Verifica se os caracteres estão minúsculos
- setlocale() - Define informações locais
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
