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

ctype函数

PHP ctype_cntrl()函数 (PHP ctype_cntrl() function)

ctype_cntrl() function is a character type (CType) function in PHP, it is used to check whether a given string contains all control characters or not.

ctype_cntrl()函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否包含所有控制字符。

It returns true if all characters of the given strings are control characters (like, a newline character, tab character, escape character etc). Else it returns false.

如果给定字符串的所有字符都是控制字符(例如,换行符,制表符,转义符等),则返回true 。 否则返回false 。

Note: Though control characters are unprintable character i.e. they cannot be represented in the string format if we represent they may display like symbols. So, we can provide the escape sequences in the string by following with forwarding slash (\), we can also provide the control character’s ASCII code in the range of hexadecimal values from 0x00 to 0x1f and 0x7f (Del).

注意:尽管控制字符是不可打印的字符,即如果我们表示它们可能显示为类似符号,则它们不能以字符串格式表示。 因此,我们可以在字符串后加上正斜杠( \ )来提供转义序列,还可以提供控制字符的ASCII代码,范围为从0x00到0x1f和0x7f (Del)的十六进制值。

To assign characters to value ASCII format (hexadecimal value), we use \x with the value.

要将字符分配给值ASCII格式(十六进制值),我们使用\ x作为值。

Syntax:

句法:

    ctype_cntrl(string) : bool

Example:

例:

    Input: "\r\n"
    Output: true
    Input: "\t\x12"
    Output: true
    Input: "\x00\x12\x1f\x7f"
    Output: true
    Input: "Hello123"
    Output: false

PHP code:

PHP代码:

<?php
    $str1 = "\r\n";
    if(ctype_cntrl($str1))
        echo ("str1 contains all control characters.\n");
    else
        echo ("str1 does not contain all control characters.\n");
    
    $str2 = "\t\x12";
    if(ctype_cntrl($str2))
        echo ("str2 contains all control characters.\n");
    else
        echo ("str2 does not contain all control characters.\n");

    $str3 = "\x00\x12\x1f\x7f";
    if(ctype_cntrl($str3))
        echo ("str3 contains all control characters.\n");
    else
        echo ("str3 does not contain all control characters.\n");        

    $str4 = "\r \n"; //space is there 
    if(ctype_cntrl($str4))
        echo ("str4 contains all control characters.\n");
    else
        echo ("str4 does not contain all control characters.\n");

    $str5 = "Hello123"; //alphabets & digits are there
    if(ctype_cntrl($str5))
        echo ("str5 contains all control characters.\n");
    else
        echo ("str5 does not contain all control characters.\n");                
?>

Output

输出量

str1 contains all control characters.
str2 contains all control characters.
str3 contains all control characters.
str4 does not contain all control characters.
str5 does not contain all control characters.


翻译自: https://www.includehelp.com/php/ctype_cntrl-function-with-example.aspx

ctype函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值