Home » PHP » PHP Ctype functions

PHP ctype_punct() function with example

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

PHP ctype_punct() function

ctype_punct() function is a character type (CType) function in PHP, it is used to check whether a given string contains all punctuation characters (can be considered as special characters) or not.

It returns true, if all characters of the given strings are punctuation characters, else it returns false.

Syntax:

    ctype_punct(string) : bool

Example:

    Input: "@!~#"
    Output: true
    Input: "@!  #~"
    Output: false
    Input: "[email protected]!"
    Output: false

PHP code:

<?php
    $str = "@!~#";
    if(ctype_punct($str))
        echo ("$str contains all punctuation characters.\n");
    else
        echo ("$str does not contain all punctuation characters.\n");

    $str = "@!  #~"; //space is there
    if(ctype_punct($str))
        echo ("$str contains all punctuation characters.\n");
    else
        echo ("$str does not contain all punctuation characters.\n");

    $str = "[email protected]!"; //alphabets are there
    if(ctype_punct($str))
        echo ("$str contains all punctuation characters.\n");
    else
        echo ("$str does not contain all punctuation characters.\n");

    $str = "@!123"; //digits are there
    if(ctype_punct($str))
        echo ("$str contains all punctuation characters.\n");
    else
        echo ("$str does not contain all punctuation characters.\n");
?>

Output

@!~# contains all punctuation characters.
@!  #~ does not contain all punctuation characters.
[email protected]! does not contain all punctuation characters.
@!123 does not contain all punctuation 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.