Friday, October 24, 2025
HomeLanguagesPHP | ctype_cntrl() Function

PHP | ctype_cntrl() Function

The ctype_cntrl() is an inbuilt function in PHP which is used to check all the characters in string/text are control characters. Control characters are e.g. line feed, tab, escape.
Syntax: 
 

bool ctype_cntrl ( $str )

Parameters: This function accepts a single parameter $str. It is a mandatory parameter which specifies the string.
Return Value: It returns True if a string contains only control characters and False on failure.
Examples: 
 

Input: neveropen
Output: No
Explanation: String (neveropen) contains only the alphanumeric characters.

Input: \n\t
Output: Yes
Explanation: String (\n\t) contains only the control character.

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

php




<?php
// PHP program to check if a string has all
// control characters
 
$str1 = "neveropen";
 
    if ( ctype_cntrl($str1))
     
        echo "Yes\n";
    else
        echo "No\n";
 
$str2 = "\n\t";
 
    if ( ctype_cntrl($str2))
     
        echo "Yes\n";
    else
        echo "No\n";
?>


Output: 

No
Yes

 

Program 2: Implementation of ctype_cntrl() function which takes input of an array of string that contains integers and special Symbol. 
 

php




<?php
// PHP program to check if a string has all
// control characters
  
$str = array(
    "Geeks",
    "Geeks space",
    "@@##-- /",
    "\n",
    "\t \r",
    "\r\t\n"
);
  
// Check the above strings by using
// ctype_cntrl() function
foreach ($str as $test) {
      
    if (ctype_cntrl($test))
        echo "Yes\n";
    else
        echo "No\n";   
}
  
?>


Output: 

No
No
No
Yes
No
Yes

 

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS