PHP | ctype_punct() Function

The ctype_punct() is an inbuilt function in PHP which is used to check printable character which is not whitespace or an alphanumeric character. Every character in a string is printable, but neither alphanumeric, digit or blank then return True otherwise return False.

Syntax:

bool ctype_punct ( $text )

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



Return Value: It returns True if string does not contain any alphanumeric, digit or blank character and False on failure.
Examples:

Input : GeeksforGeeks
Output : No
Explanation: String (GeeksforGeeks) contains only the alphanumeric characters.

Input : $%^&@
Output : Yes
Explanation: String ($%^&@) contains only the punctuation character.

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check the given
// string is not containing any 
// alphanumeric or digit or blank
// character
  
$string1 = 'GeeksforGeeks';
if ( ctype_punct($string1)) 
        echo "Yes\n";
    else
        echo "No\n";
  
$string2 = '$%^&@';
if ( ctype_punct($string2)) 
        echo "Yes\n";
    else
        echo "No\n";
?>

chevron_right


Output:

No
Yes

Program 2: Code for ctype_punct() function accepts input array of string which contains integers and special Symbol.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check given
// string is not contain any 
// alphanumeric or digit or
// blank character
  
$strings = array (
    'Geeks',
    'Geeks space',
    '@@##-- /',
    '12345',
    '\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
No
No
No
No
Yes

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.