= 4.0.4, PHP 5, PHP 7, PHP 8)ctype_punct — 檢測可打印的字符是不是不包含空白、數(shù)字和字母 說明ctype_punct(string $text): bool檢查提供的 string 和 text 里面的字符是不是都是標點">

ctype_punct

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

ctype_punct 檢測可打印的字符是不是不包含空白、數(shù)字和字母

說明

ctype_punct(string $text): bool

檢查提供的 stringtext 里面的字符是不是都是標點符號。

參數(shù)

text

需要被測試的字符串。

返回值

如果在 text 里面的每個字符都是能打印的,但不是字母、數(shù)字,也不是空白,那么就返回 true ;反之則返回 false 。

范例

示例 #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.

注釋

注意:

如果給出一個 -128 到 255 之間(含)的int, 將會被解釋為該值對應的ASCII字符 (負值將加上 256 以支持擴展ASCII字符). 其它整數(shù)將會被解釋為該值對應的十進制字符串.

參見