ctype_upper

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

ctype_upperControlla i caratteri maiuscoli

Descrizione

ctype_upper(mixed $text): bool

Controlla che tutti i caratteri nella string, text fornita, siano caratteri maiuscoli.

Elenco dei parametri

text

La stringa da testare.

Nota:

Se è fornito un integer tra -128 e 255, viene interpretato come il valore ASCII di un singolo carattere (ai valori negativi viene aggiunto 256 in modo da permettere i caratteri Extended ASCII). Qualsiasi altro intero è interpretato come una stringa contenente le cifre decimali dell'intero.

Avviso

As of PHP 8.1.0, passing a non-string argument is deprecated. In the future, the argument will be interpreted as a string instead of an ASCII codepoint. Depending on the intended behavior, the argument should either be cast to string or an explicit call to chr() should be made.

Valori restituiti

Restituisce true se ogni carattere di text è una lettera maiuscola nel locale corrente. When called with an empty string the result will always be false.

Esempi

Example #1 Un esempio di ctype_upper() (usando il locale di default)

<?php
$strings
= array('AKLWC139', 'LMNSDO', 'akwSKWsm');
foreach (
$strings as $testcase) {
if (
ctype_upper($testcase)) {
echo
"The string $testcase consists of all uppercase letters.\n";
} else {
echo
"The string $testcase does not consist of all uppercase letters.\n";
}
}
?>

Il precedente esempio visualizzerà:

The string AKLWC139 does not consist of all uppercase letters.
The string LMNSDO consists of all uppercase letters.
The string akwSKWsm does not consist of all uppercase letters.

Vedere anche:

add a note

User Contributed Notes 2 notes

up
6
chris at theothernews dot co dot nz
9 years ago
Underscores in the string will result in false, so you have to remove them first.
up
-25
Anonymous
8 years ago
// after screwing around with function.ctype-upper
// I found this simple solution

if (strtolower($string) != $string)// its so simple!
{
echo "uppercase letters found in $string";
}

source: http://stackoverflow.com/questions/4426327/how-to-detect-if-string-contains-1-uppercase-letter-in-php
To Top