ctypealpha php_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;
[
$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;
$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"; \\ 输出 The string arf12 does not consist of all letters.
}
}
?>
3、ctype_cntrl — Check for control character(s) 检查字符串中是否只包含" '\n' '\r' '\t' " 这样的控制字符。
$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) 检查字符串中是否只包含数字
$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";
}
}
?>
ctypealpha php_php ctype函数中文翻译和示例相关推荐
- ctypealpha php_PHP Ctype函数(转)
Ctype函数是PHP内置的字符串体测函数.主要有以下几种 ctype_alnum -- Check for alphanumeric character(s) 检测是否是只包含[A-Za-z0-9] ...
- LoadRunner函数中文翻译
LoadRunner函数中文翻译系列之一--Action web_url 语法: Int Web_url(const char *name, const char * url, <Lists o ...
- ctypealpha php_php中Ctype函数用法详解
本文实例分析了php中Ctype函数用法.分享给大家供大家参考.具体分析如下: Ctype函数是Php的Ctype扩展函数提供了一组函数用于校验字符串中的字符是否是正确的格式,这里我们主要介绍一下这些 ...
- ctype函数_PHP ctype_xdigit()函数与示例
ctype函数 PHP ctype_xdigit()函数 (PHP ctype_xdigit() function) ctype_xdigit() function is a character ty ...
- ctype函数_PHP ctype_cntrl()函数与示例
ctype函数 PHP ctype_cntrl()函数 (PHP ctype_cntrl() function) ctype_cntrl() function is a character type ...
- 《Introduction to Tornado》中文翻译计划——第五章:异步Web服务
http://www.pythoner.com/294.html 本文为<Introduction to Tornado>中文翻译,将在https://github.com/alioth3 ...
- ctype函数_PHP Ctype(字符类型)函数
ctype函数 Ctype功能 (Ctype functions) PHP provides some of the built-in functions, which are used to ver ...
- Z-Stack Home Developer's Guide—2. Overview中文翻译【Z-Stack Home 1.2.0开发文档】
下面是Z-Stack Home 1.2.0开发资料中的Z-Stack Home Developer's Guide-2. Overview的中文翻译 2.1 简介 这章节将介绍 Z-Stack协议栈的 ...
- Z-Stack Home Developer's Guide—3. The Home Automation Profile and the Sample Applications中文翻译
下面是Z-Stack Home 1.2.0开发资料中的Z-Stack Home Developer's Guide-3. The Home Automation Profile and the Sam ...
最新文章
- QML for Android 加载图片资源的几种方式
- python第三天习题
- Linux下CMAKE编译jsoncpp,c – 如何为jsoncpp编写cmake模块?
- 如何查看git是否添加到环境变量 - cmd篇
- 超简单利用xposed框架破解钉钉打卡
- RTT设置删除空闲钩子函数想到函数指针和回调函数
- sqli-lab(8)
- Node之HTTPS客户端
- 修改devcpp5.11的语言选项
- rufus(u盘引导盘制作工具) v3.5.1497
- 常用公差配合表图_车间里常用的机械测量工具竟然这么多?
- 一名合格的Web前端工程师需要具备的8项技能!
- BSB网络验证 易语言网络验证系统 autojs 网络验证系统 免费的卡密收费系统 账号注册系统
- 95%以上的日常办事启用电子签章,你都体验过哪些?
- 十、Linux开发板控制LED灯设备
- JAVA学习导图、思维导图
- LLC谐振变换器工作模态分析
- CMDB建设补充:教你用django+drf 怎么去生成漂亮的API文档
- 中兴对华为NB-IoT的大反击 - CLAA
- 非零基础自学Golang 第15章 Go命令行工具 15.4 注释文档(doc)