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" ; ?> |
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" ; } ?> |
No No No Yes No Yes
References: http://php.net/manual/en/function.ctype-cntrl.php