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: GeeksforGeeks
Output: No
Explanation: String (GeeksforGeeks) 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
$str1 = "GeeksforGeeks" ;
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" ;
?>
|
Program 2: Implementation of ctype_cntrl() function which takes input of an array of string that contains integers and special Symbol.
php
<?php
$str = array (
"Geeks" ,
"Geeks space" ,
"@@##-- /" ,
"\n" ,
"\t \r" ,
"\r\t\n"
);
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
Last Updated :
30 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...