Computer >> Computer tutorials >  >> Programming >> PHP

ctype_punct() function in PHP


The ctype_punct() function check for any printable character which is not whitespace or an alphanumeric character.

Syntax

ctype_punct(str)

Parameters

  • str − The tested string

Return

The ctype_punct() function returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.

Example

The following is an example −

<?php
   $srr = array('k211!@!$#', 'foo!#$bar', '*$()');

   foreach ($srr as $d) {
      if (ctype_punct($d)) {
         echo "$d consists of all punctuation. \n";
      } else {
         echo "$d does not have all punctuation. \n";
      }
   }
?>

Output

The following is the output −

k211!@!$# does not have all punctuation.
foo!#$bar does not have all punctuation.
*$() consists of all punctuation.