downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ctype_cntrl> <ctype_alnum
[edit] Last updated: Fri, 17 May 2013

view this page in

ctype_alpha

(PHP 4 >= 4.0.4, PHP 5)

ctype_alphaControlla i caratteri alfabetici

Descrizione

bool ctype_alpha ( string $testo )

Restituisce TRUE se ogni carattere di testo è una lettera dell'ambiente corrente, FALSE in caso contrario. Nell'ambiente standard del C le lettere sono solo [A-Za-z] e ctype_alpha() è equivalente a (ctype_upper($text) || ctype_lower($text)), se $text è di un singolo carattere, ma altri linguaggi hanno lettere che non sono considerate nè maiuscole nè minuscole.

Example #1 Esempio di uso di ctype_alpha() (utilizzando le impostazioni locali di default)

<?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";
    }
}
?>

This example will output :

The string KjgWZC consists of all letters.
The string arf12 does not consists of all letters.

Vedere anche ctype_upper(), ctype_lower() e setlocale().



add a note add a note User Contributed Notes ctype_alpha - [2 notes]
up
-1
Tyrunur
4 years ago
It works if you set the locale correctly:

<?php

setLocale
(LC_CTYPE, 'FR_fr.UTF-8');

?>

with this change you will get "yes" "yes"
up
-1
jerome at yazo dot net
4 years ago
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

 
show source | credits | stats | sitemap | contact | advertising | mirror sites