(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_punct — 檢查是否為任何可列印字元,但非空白或英數字元
text
要測試的字串。
注意事項:
如果提供 -128 到 255 之間(含)的整數 (int),它會被解釋為單個字元的 ASCII 值(負值會加上 256,以便允許擴展 ASCII 範圍中的字元)。任何其他整數都會被解釋為包含該整數十進制數字的字串。
從 PHP 8.1.0 開始,不建議傳遞非字串的參數。未來,該參數將被解釋為字串,而不是 ASCII 字碼點。根據預期的行為,應該將參數強制轉換為字串 (string)或明確呼叫chr()。
範例 #1 ctype_punct() 範例
<?php
$strings = array('ABasdk!@!$#', '!@ # $', '*&$()');
foreach ($strings as $testcase) {
if (ctype_punct($testcase)) {
echo "字串 $testcase 全由標點符號組成。\n";
} else {
echo "字串 $testcase 並非全由標點符號組成。\n";
}
}
?>
以上範例將輸出
The string ABasdk!@!$# does not consist of all punctuation. The string !@ # $ does not consist of all punctuation. The string *&$() consists of all punctuation.