PHP | ctype_print() Function

The ctype_print() Function in PHP used to check each and every character of a string are visible or not. If all characters of string are visible then returns TRUE , else if there are any control character then return 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 which is not printable but perform action “Next Line”

Syntax:



ctype_print(string text)

Parameter Used:

  • $text : The tested string. Its a mandatory parameter.

Return Values:
This function return TRUE if all characters of string are printable(not containing any control character). And return FALSE if string contains any control character.

Examples:

Input  : Geeks for geeks article
Output : Geeks for geeks article -->Yes visible

Explanation : The string contains three blank space 
             and the function returns TRUE. 

Input  : \tgfg\n
Output :     gfg
--> No visible

Explanation : '\t' and '\n' are control character .
            Then the function returns False.
                   

Program: 1

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to illustrate 
// ctype_print() function 
  
$string = 'GFG A Computer Science Portal';
  
// Checking above given strings 
// by used of ctype_print() function .
if (ctype_print($string)) {
      
    // if true then return Yes
    echo "$string: Yes visible\n";
} else {
      
    // if False then return No
    echo "$string: Not visible\n";
}
?>

chevron_right


Output:

GFG A Computer Science Portal: Yes visible

Program: 2 Drive a code of ctype_print() function where input will be integer, symbols in array of strings.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to illustrate
// ctype_print() function 
  
$strings = array(
    "GeeksforGeeks",
    "GFG2018",
    "\nComputerScience",
    "G 4 G",
    "@#$$.&*()_+;?~",
    "78 96 . 90"
);
  
// Checking above array of strings 
// by used of ctype_print() function.
foreach ($strings as $str) {
      
    if (ctype_print($str)) {
          
        // if true then return Yes
        echo "$str:   (Yes visible)\n";
    } else {
        // if False then return No
        echo "$str:   (No visible)\n";
    }
}
  
?>

chevron_right


Output:

GeeksforGeeks:   (Yes visible)
GFG2018:   (Yes visible)

ComputerScience:   (No visible)
G 4 G:   (Yes visible)
@#$$.&*()_+;?~:   (Yes visible)
78 96 . 90:   (Yes visible)

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.