ctype函数
PHP ctype_graph()函数 (PHP ctype_graph() function)
ctype_graph() function is a character type (CType) function in PHP, it is used to check whether a given string contains all printable characters (except space) or not.
ctype_graph()函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否包含所有可打印字符(空格除外)。
It returns true if all characters of the given strings are printable characters except whitespace. 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. But, this function does not consider space as a printable character.
可打印字符是可以在屏幕上打印的字符。 所有字母,数字,空格和特殊字符均为可打印字符。 但是,此函数不将空格视为可打印字符 。
Syntax:
句法:
ctype_graph(string) : bool
Example:
例:
Input: "Hello123"
Output: true
Input: "[email protected]#!~*.()"
Output: true
Input: "Hello world!"
Output: false
Input: "Hello\r\nWorld"
Output: false
Input: "Hello\x41"
Output: true
PHP code:
PHP代码:
<?php
$str = "Hello123";
if(ctype_graph($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
$str = "[email protected]#!~*.()";
if(ctype_graph($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
$str = "Hello World";
if(ctype_graph($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_graph($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_graph($str))
echo ("$str contains all printable characters.\n");
else
echo ("$str does not contain all printable characters.\n");
?>
Output
输出量
Hello123 contains all printable characters.
[email protected]#!~*.() contains all printable characters.
Hello World does not contain all printable characters.
Hello
World does not contain all printable characters.
HelloA contains all printable characters.
翻译自: https://www.includehelp.com/php/ctype_graph-function-with-example.aspx
ctype函数