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.
TOP Interview Coding Problems/Challenges