≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > PHP笔记

php ctype函数中文翻译的简单示例

人气:212 时间:2021-08-24

这篇文章主要为大家详细介绍了php ctype函数中文翻译的简单示例,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小玲来看看吧!

PHP Ctype扩展是PHP4.2开始就内建的扩展,注意,Ctype系列函数都只有一个字符串类型参数,它们返回布尔值。

 

代码如下:


$str = "0.1123";
//检查字符串所有字符是否为数字
echo "ctype_digit:" . ctype_digit($str);  //空
//检测是否为数字字符串,可为负数和小数
echo "is_numberic:" . is_numeric($str); //1

 

从上面可以看出ctype_digit()和is_numberic()的区别。

中文翻译

Ctype函数是PHP内置的字符串体测函数。主要有以下几种

ctype_alnum -- Check for alphanumeric character(s)
检测是否是只包含[A-Za-z0-9]

ctype_alpha -- Check for alphabetic character(s)
检测是否是只包含[A-Za-z]

ctype_cntrl -- Check for control character(s)
检查是否是只包含类是“\n\r\t”之类的字 符控制字符

ctype_digit -- Check for numeric character(s)
检查时候是只包含数字字符的字符串(0-9)

ctype_graph -- Check for any printable character(s) except space
检查是否是只包含有可以打印出来的字符(除了空格)的字符串

ctype_lower -- Check for lowercase character(s)
检查是否所有的字符都是英文字母,并且都是小写的

ctype_print -- Check for printable character(s)
检查是否是只包含有可以打印出来的字符的字符串

ctype_punct -- Check for any printable character which is not whitespace or an alphanumeric character
检查是否是只包含非数字/字符/空格的可打印出来的字符

ctype_space -- Check for whitespace character(s)
检查是否是只包含类是“ ”之类的字符和空格

ctype_upper -- Check for uppercase character(s)
检查是否所有的字符都是英文字母,并且都是大写的

ctype_xdigit -- Check for character(s) representing a hexadecimal digit
检查是否是16进制的字符串,只能包括 “0123456789abcdef”

有示例的哟

我们平常在遇到要对一些表单做简单过滤的时候,往往不太愿意写正则,而且在效率上,正则也是影响PHP运行速度的原因之一,所以在能不试用正则的时候尽量不试用正则。幸好PHP已经为我们考虑到了这一点,给我提供了Ctype函数。下面对一些Ctype函数做一些简单介绍,以备用:
1、ctype_alnum — Check for alphanumeric character(s)   检查字符串中只包含数字或字母,相当于正则[A-Za-z0-9].   有返回值。成功时返回TRUE,失败为FALSE;
[

代码如下:


<?php
/*   四海网 www.q1010.com   */
  
$strings = array('AbCd1zyZ9', 'foo!#$bar');  
foreach ($strings as $testcase) {  
    if (ctype_alnum($testcase)) {  
        echo "The string $testcase consists of all letters or digits.\n"; \\ 输出The string AbCd1zyZ9 consists of all letters or digits.  
    } else {  
        echo "The string $testcase does not consist of all letters or digits.\n"; \\ 输出 The string foo!#$bar does not consist of all letters or digits.  
    }  
}  
?>  

 

2、ctype_alpha — Check for alphabetic character(s)  检查字符串中只包含字母。  成功时返回TRUE,失败为FALSE;

代码如下:


<?php
/*   四海网 www.q1010.com   */
  
$strings = array('KjgWZC', 'arf12');  
foreach ($strings as $testcase) {  
    if (ctype_alpha($testcase)) {  
        echo "The string $testcase consists of all letters.\n"; \\ 输出 The string KjgWZC consists of all letters.  
    } else {  
        echo "The string $testcase does not consist of all letters.\n";<span style="white-space:pre">   </span>\\ 输出 The string arf12 does not consist of all letters.  
    }  
}  
?>  

 

3、ctype_cntrl — Check for control character(s)    检查字符串中是否只包含" '\n' '\r' '\t' " 这样的控制字符。

代码如下:


<?php
/*   四海网 www.q1010.com   */
  
$strings = array('string1' => "\n\r\t", 'string2' => 'arf12');  
foreach ($strings as $name => $testcase) {  
    if (ctype_cntrl($testcase)) {  
        echo "The string '$name' consists of all control characters.\n"; \\ 输出 The string 'string1' consists of all control characters.  
    } else {  
        echo "The string '$name' does not consist of all control characters.\n"; \\ The string 'string2' does not consist of all control characters.  
    }  
}  
?>   

 

4、ctype_digit — Check for numeric character(s) 检查字符串中是否只包含数字

代码如下:


<?php
/*   四海网 www.q1010.com   */
  
$strings = array('1820.20', '10002', 'wsl!12');  
foreach ($strings as $testcase) {  
    if (ctype_digit($testcase)) {  
        echo "The string $testcase consists of all digits.\n";  
    } else {  
        echo "The string $testcase does not consist of all digits.\n";  
    }  
}  
?>   

 

本文来自:http://www.q1010.com/173/16582-0.html

注:关于php ctype函数中文翻译的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:ctype

您可能感兴趣的文章

上一篇:php 使用GD库为页面增加水印的简单示例
下一篇:php像数组一样存取和修改字符串字符的简单示例
热门文章
  • PHP 写入WRITE编码为UTF8的文件示例
  • PHP 中文字符串截取函数示例:支持gb2312,gbk,big
  • PHP 简单留言板的制作示例
  • 解决Fatal error: Call to undefined function mb_convert_encoding() in错误问题
  • PHP语言基础(标记、注释、变量、数组、常量、函数)示例
  • php 生成迅雷链接的简单示例
  • php 获取短网址的实现方法
  • PHP 通用分页类的简单示例
  • PHP 使用文件方式导入导出整个MYSQL数据库的实现方法
  • php 获取MYSQL错误的简单示例
  • 最新文章
    • 解决PHP使用redis实现统计缓存MySQL压力的问题
    • php 简单的上传进度条的简单示例
    • php 给html中引用的js和css路径打上版本号的实现方法
    • php 实现计算年龄精准到年月日的实例
    • php+ajax无刷新分页的简单示例
    • 解决php+ajax无刷新上传图片的问题
    • 解决PHP生成HTML静态页面的问题
    • 解决PHP使用uniqid函数生成唯一ID的问题
    • 解决PHP防刷票的一些问题
    • 微信access_token的获取开发的实现方法

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。