Home » PHP » PHP Ctype functions

PHP ctype_print() function with example

PHP ctype_print() function: Here, we are going to learn about the ctype_print() function with example in PHP.
Submitted by IncludeHelp, on February 04, 2019

PHP ctype_print() function

ctype_print() function is a character type (CType) function in PHP, it is used to check whether a given string contains all printable characters or not.

It returns true, if all characters of the given strings are printable. Else it returns false.

Printable characters are the characters that can be printed on the screen. The all alphabets, digits, whitespace and special characters are the printable characters.

Syntax:

    ctype_print(string) : bool

Example:

    Input: "Hello 123"
    Output: true
    Input: "I am [email protected]#!~*.()"
    Output: true
    Input: "Hello\r\nWorld"
    Output: false
    Input: "Hello\x41"
    Output: true

PHP code:

<?php
    $str = "Hello 123";
    if(ctype_print($str))
        echo ("$str contains all printable characters.\n");
    else
        echo ("$str does not contain all printable characters.\n");

    $str = "I am [email protected]#!~*.()";
    if(ctype_print($str))
        echo ("$str contains all printable characters.\n");
    else
        echo ("$str does not contain all printable characters.\n");

    $str = "Hello\r\nWorld"; //"\r" and "\n" are not printable characters
    if(ctype_print($str))
        echo ("$str contains all printable characters.\n");
    else
        echo ("$str does not contain all printable characters.\n");

    $str = "Hello\x41"; //"\x41" is the ASCII value of "A"
    if(ctype_print($str))
        echo ("$str contains all printable characters.\n");
    else
        echo ("$str does not contain all printable characters.\n");	
?>

Output

Hello 123 contains all printable characters.
I am [email protected]#!~*.() contains all printable characters.
Hello
World does not contain all printable characters.
HelloA contains all printable characters.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.