PHP | ctype_cntrl() Function
Last Updated :
17 May, 2021
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
$string = "\n" ;
if ( ctype_cntrl( $string ))
echo "Yes\n" ;
else
echo "No\n" ;
?>
|
Program: 2
PHP
<?php
$strings = array ( "\c" , "\f" , "\n" , "\\" , "123" , "GFG" );
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
Share your thoughts in the comments
Please Login to comment...