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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值