PHP | ctype_cntrl() Function

The ctype_cntrl() function is an inbuilt function in PHP and is used to check if all of the characters of a given string are control characters or not. It returns True if all characters of the string are control characters otherwise it returns false.

Control Character: A character that does not represent a printable character but serves to initiate a particular action. For example ‘\n’ is a control character which is not printable but perform action “Next Line”.

Syntax:

ctype_cntrl( $text )

Parameters: The function accepts a single parameter $text which represents the input string.

Return Value: This function returns TRUE if all characters of the string are Control Character otherwise it returns FALSE.



Examples:

Input  : "\t"
Output : Yes

Input  : "\\\b"
Output : No                 

Below programs illustrate the ctype_cntrl() function:
Program: 1

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check given string has all
// characters as control character
  
$string = "\n";
  
// Checking above given strings 
// by used of ctype_cntrl() function
if ( ctype_cntrl($string)) 
    echo "Yes\n";
else 
    // if False then return No
    echo "No\n";
?>

chevron_right


Output:

Yes

Program: 2

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to ilustrate the ctype_cntrl() function
   
$strings = array("\c", "\f", "\n", "\\","123","GFG");
   
// Checking above given strings 
// by use of ctype_cntrl() function .
foreach ($strings as $test) {
       
    if ( ctype_cntrl($test)) 
        echo "Yes\n";
    else
        echo "No\n";
}
?>

chevron_right


Output:

No
Yes
Yes
No
No
No

Reference : http://php.net/manual/en/function.ctype-cntrl.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.