ctype函数
PHP ctype_print()函数 (PHP ctype_print() function)
ctype_print() function is a character type (CType) function in PHP, it is used to check whether a given string contains all printable characters or not.
ctype_print()函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否包含所有可打印字符。
It returns true, if all characters of the given strings are printable. Else it returns false.
如果给定字符串的所有字符均可打印,则返回true 。 否则返回false 。
Printable characters are the characters that can be printed on the screen. The all alphabets, digits, whitespace and special characters are the printable characters.
可打印字符是可以在屏幕上打印的字符 。 所有字母,数字,空格和特殊字符均为可打印字符。
Syntax:
句法:
ctype_print(string) : bool
Example:
例:
Input: "Hello 123"
Output: true
Input: "I am [email protected]#!~*.()"
Output: true
Input: "Hello\r\nWorld"
Output: false
Input: "Hello\x41"
Output: true
PHP code:
PHP代码:
<?php
$str = "Hello 123";
if(ctype_print($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
$str = "I am [email protected]#!~*.()";
if(ctype_print($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
$str = "Hello\r\nWorld"; //"\r" and "\n" are not printable characters
if(ctype_print($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
$str = "Hello\x41"; //"\x41" is the ASCII value of "A"
if(ctype_print($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
?>
Output
输出量
Hello 123 contains all printable characters.
I am [email protected]#!~*.() contains all printable characters.
Hello
World does not contain all printable characters.
HelloA contains all printable characters.
翻译自: https://www.includehelp.com/php/ctype_print-function-with-example.aspx
ctype函数