English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_punct() Function Usage and Example

PHP Ctype Function Manual

 The ctype_punct() function checks if printable characters do not include whitespace, numbers, and letters.

Syntax

ctype_punct($text);

Definition and usage

This function checks if all characters in the provided string are punctuation symbols.

Parameter

Serial numberParameters and descriptions
1

text (required)

The string being tested

Return value

 If each character in the text is printable but not a letter, number, or whitespace, it returns TRUE; otherwise, it returns FALSE.

Online example

An instance of ctype_punct() to check if characters are all punctuation symbols.

<?php
   $strings = array('k211!@!$#, 'foo!#$bar', ''*$());
   
   foreach ($strings as $test) {
      if (ctype_punct($test)) {
         echo "$test Punctuation marks \n";
      }else {
         echo "$test Non-punctuation characters \n";
      }
   }
?>
Test and see‹/›

Output result:

k211!@!$# Non-punctuation characters 
foo!#$bar Non-punctuation characters 
*Punctuation marks

   PHP Ctype Function Manual