Open In App

PHP | ctype_cntrl() Function

Last Updated : 17 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The ctype_cntrl() function is an inbuilt function in PHP and is used to check if all 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 that is not printable but performs the 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 
 

PHP




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


Output: 

Yes

 

Program: 2
 

PHP




<?php
// PHP program to illustrate 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";
}
?>


Output: 

No
Yes
Yes
No
No
No

 

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads