ctype_cntrl()函數是PHP中的內置函數,用於檢查給定字符串的所有字符是否都是控製字符。如果字符串的所有字符都是控製字符,則返回True,否則返回false。
控製字符:不代表可打印字符但用於啟動特定操作的字符。例如,“ \ n”是一個不可打印的控製字符,但會執行“Next Line”操作。
用法:
ctype_cntrl( $text )
參數:該函數接受表示輸入字符串的單個參數$text。
返回值:如果字符串的所有字符均為控製字符,則此函數返回TRUE,否則返回FALSE。
例子:
Input :"\t" Output:Yes Input :"\\\b" Output:No
以下示例程序旨在說明ctype_cntrl()函數:
程序:1 
<?php 
// PHP program to check given string has all 
// characters as control character 
  
$string = "\n"; 
  
// Checking above given strings  
// by used of ctype_cntrl() function 
if ( ctype_cntrl($string))  
    echo "Yes\n"; 
else 
    // if False then return No 
    echo "No\n"; 
?>
輸出:
Yes
程序:2
<?php 
// PHP program to ilustrate the ctype_cntrl() function 
   
$strings = array("\c", "\f", "\n", "\\","123","GFG"); 
   
// Checking above given strings  
// by use of ctype_cntrl() function . 
foreach ($strings as $test) { 
       
    if ( ctype_cntrl($test))  
        echo "Yes\n"; 
    else
        echo "No\n"; 
} 
?>
輸出:
No Yes Yes No No No
參考:http://php.net/manual/zh/function.ctype-cntrl.php
相關用法
- d3.js d3.lab()用法及代碼示例
 - PHP exp()用法及代碼示例
 - PHP Ds\Map put()用法及代碼示例
 - d3.js d3.hcl()用法及代碼示例
 - PHP sin( )用法及代碼示例
 - PHP abs()用法及代碼示例
 - PHP cos( )用法及代碼示例
 - PHP tan( )用法及代碼示例
 - d3.js d3.map.set()用法及代碼示例
 - PHP next()用法及代碼示例
 - PHP Ds\Map get()用法及代碼示例
 - d3.js d3.sum()用法及代碼示例
 
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ctype_cntrl() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
