Check for any printable character which is not whitespace or an alphanumeric character with ctype_punct in PHP

Description

The following code shows how to check for any printable character which is not whitespace or an alphanumeric character with ctype_punct.

Example


//from w  w  w. ja  v  a 2 s.c o  m
<?php
$strings = array('234fsdfasdf234!@!$#', '!@ # $', '*&$()');
foreach ($strings as $testcase) {
    if (ctype_punct($testcase)) {
        echo "The string $testcase consists of all punctuation.\n";
    } else {
        echo "The string $testcase does not consist of all punctuation.\n";
    }
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone