PHP - Function ctype_punct()


Advertisements


Syntax

ctype_punct ( $text );

Definition and Usage

This function checks if all of the characters in the provided string, text, are punctuation character.

Parameters

Sr.No Parameter & Description
1

text

Required. The tested string.

Return Value

Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.

Example

Try out following example −

<?php
   $strings = array('ABasdk!@!$#', 'foo!#$bar', '*$()');
   
   foreach ($strings as $testcase) {
      if (ctype_punct($testcase)) {
         echo "$testcase consists of all punctuation. \n";
      }else {
         echo "$testcase does not have all punctuation. \n";
      }
   }
?> 

This will produce the following result −

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

php_function_reference.htm