PHP中的ctype_print()函數用於檢查字符串的每個字符是否可見。如果字符串的所有字符均可見,則返回TRUE,否則,如果有任何控製字符,則返回FALSE。
控製字符:不代表可打印字符但用於啟動特定操作的字符。例如“ \ n”是一個不可打印的控製字符,但會執行“Next Line”操作
用法:
ctype_print(string text)
使用的參數:
- $text : 測試的字符串。它是必填參數。
返回值:
如果字符串的所有字符都是可打印的(不包含任何控製字符),則此函數返回TRUE。如果字符串包含任何控製字符,則返回FALSE。
例子:
Input  : Geeks for geeks article
Output : Geeks for geeks article -->Yes visible
Explanation : The string contains three blank space 
             and the function returns TRUE. 
Input  : \tgfg\n
Output :     gfg
--> No visible
Explanation : '\t' and '\n' are control character .
            Then the function returns False.
                   
程序:1
<?php 
// PHP program to illustrate  
// ctype_print() function  
  
$string = 'GFG A Computer Science Portal'; 
  
// Checking above given strings  
// by used of ctype_print() function . 
if (ctype_print($string)) { 
      
    // if true then return Yes 
    echo "$string: Yes visible\n"; 
} else { 
      
    // if False then return No 
    echo "$string: Not visible\n"; 
} 
?>
輸出:
GFG A Computer Science Portal: Yes visible
程序:2驅動ctype_print()函數的代碼,其中輸入將是整數,即字符串數組中的符號。
<?php 
// PHP program to illustrate 
// ctype_print() function  
  
$strings = array( 
    "GeeksforGeeks", 
    "GFG2018", 
    "\nComputerScience", 
    "G 4 G", 
    "@#$$.&*()_+;?~", 
    "78 96 . 90"
); 
  
// Checking above array of strings  
// by used of ctype_print() function. 
foreach ($strings as $str) { 
      
    if (ctype_print($str)) { 
          
        // if true then return Yes 
        echo "$str:   (Yes visible)\n"; 
    } else { 
        // if False then return No 
        echo "$str:   (No visible)\n"; 
    } 
} 
  
?>
輸出:
GeeksforGeeks: (Yes visible) GFG2018: (Yes visible) ComputerScience: (No visible) G 4 G: (Yes visible) @#$$.&*()_+;?~: (Yes visible) 78 96 . 90: (Yes visible)
參考:http://php.net/manual/zh/function.ctype-print.php
相關用法
- p5.js day()用法及代碼示例
- PHP dir()用法及代碼示例
- PHP each()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js second()用法及代碼示例
- p5.js int()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js str()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ctype_print() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
