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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
