English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_cntrl() Function Usage and Example

PHP Ctype Function Manual

The ctype_cntrl() function checks if all characters in the string are control characters.

Syntax

ctype_cntrl($text);

Definition and usage

Check if all characters in the provided string text are control characters. Control characters are for example: newline, indentation, space, tab, escape character, etc.

Parameter

Serial numberParameters and descriptions
1

text(Required)

The string to be tested

Return value

If each character in the text is a control character in the current language environment, it returns TRUE; otherwise, it returns FALSE.

Online Example

Determine if the string is entirely control characters:

<?php
$strings = array('string1=> '\n\r\t', 'string2=> 'arf12');
foreach ($strings as $name => $testcase) {
    if (ctype_cntrl($testcase)) {
        echo "String '$name' is composed of control characters.\n";
    } else {
        echo "String '$name' is not all control characters.\n";
    }
}
?>
Test and see‹/›

Output result:

String 'string1is composed of control characters.
String 'string2Not all are control characters.

PHP Ctype Function Manual