PHP | ctype_punct() Function

The ctype_punct() function in PHP is used to check if all of the characters of a given string are punctuation characters or not. If all characters are punctuation characters then this function return TRUE, otherwise, returns FALSE.

Note: The punctuation characters are, period, comma, question mark, hyphen, dash, parentheses, apostrophe, ellipsis, quotation mark, colon, semicolon, exclamation point.

Syntax:



ctype_punct( $text )

Parameters: This function accepts a single parameter text. It is a mandatory parameter which specifies the input string.

Return Value: The function returns TRUE if every character in $text are punctuation, otherwise it returns False.

Examples:

Input  : @#$$.&*()_+;><?~
Output : Yes

Input  : GeeksforGeeks@2018
Output : No

Note: The string should not contain a letter, blank-space  or digit.  

Below programs illustrate the ctype_punct() function:
Program: 1

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check given string is 
// punctuation character or not
  
$string = 'GeeksforGeeks';
  
  
      
    if ( ctype_punct($string)) 
        echo "Yes \n";
     else 
        echo "No \n";
  
?>

chevron_right


Output:

No

Program: 2

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check given string is 
// punctuation character or not
$strings = array(
    "Reg no CE:20",
    '()()()()',
    'GFG',
    '@@@@##$$%%^^',
    '\n'
);
  
// Checking above given strings 
//by used of ctype_punct() function .
foreach ($strings as $test) {
    if (ctype_punct($test))
        echo "Yes \n";
    else
        echo "No \n";
}
  
?>

chevron_right


Output:

No 
Yes 
No 
Yes 
No

Reference : http://php.net/manual/en/function.ctype-punct.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.