ctype函数_PHP ctype_graph()函数与示例

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函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值