ctype_punct

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

ctype_punct 检测可打印的字符是不是不包含空白、数字和字母

说明

ctype_punct ( string $text ) : bool

检查提供的 stringtext 里面的字符是不是都是标点符号。

参数

text

需要被测试的字符串。

返回值

如果在 text 里面的每个字符都是能打印的,但不是字母、数字,也不是空白,那么就返回 TRUE ;反之则返回 FALSE

范例

Example #1 一个 ctype_punct() 的例子

<?php
$strings 
= array('ABasdk!@!$#''!@ # $''*&$()');
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 string ABasdk!@!$# does not consist of all punctuation.
The string !@ # $ does not consist of all punctuation.
The string *&$() consists of all punctuation.

注释

Note:

如果给出一个 -128 到 255 之间(含)的整数, 将会被解释为该值对应的ASCII字符 (负值将加上 256 以支持扩展ASCII字符). 其它整数将会被解释为该值对应的十进制字符串.

参见