欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > php >内容正文

php

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

发布时间:2025/3/11 php 69 豆豆
生活随笔 收集整理的这篇文章主要介绍了 ctype函数_PHP ctype_xdigit()函数与示例 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

ctype函数

PHP ctype_xdigit()函数 (PHP ctype_xdigit() function)

ctype_xdigit() function is a character type (CType) function in PHP, it is used to check whether a given string contains hexadecimal digits or not.

ctype_xdigit()函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否包含十六进制数字。

It returns true, if all characters of the given strings are hexadecimal digits – which are 0,1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,a,b,c,d,e,f. Else it returns false.

如果给定字符串的所有字符均为十六进制数字(即0、1、2、3、4、5、6、7、8、9、0,A,B,C,D,E,F) ,则返回true ,a,b,c,d,e,f 。 否则返回false 。

Syntax:

句法:

ctype_xdigit(string) : bool

Example:

例:

Input: "ABCD1209"Output: trueInput: "9009aaff"Output: trueInput: "1234"Output: trueInput: "123G4"Output: false

PHP code:

PHP代码:

<?php$str = "ABCD1209";if(ctype_xdigit($str))echo ("$str contains all hexadecimal digits.\n");elseecho ("$str does not contain all hexadecimal digits.\n");$str = "9009aaff";if(ctype_xdigit($str))echo ("$str contains all hexadecimal digits.\n");elseecho ("$str does not contain all hexadecimal digits.\n");$str = "1234";if(ctype_xdigit($str))echo ("$str contains all hexadecimal digits.\n");elseecho ("$str does not contain all hexadecimal digits.\n");$str = "123G4"; //Here, "G" is not an hexadecimal digitif(ctype_xdigit($str))echo ("$str contains all hexadecimal digits.\n");elseecho ("$str does not contain all hexadecimal digits.\n"); ?>

Output

输出量

ABCD1209 contains all hexadecimal digits. 9009aaff contains all hexadecimal digits. 1234 contains all hexadecimal digits. 123G4 does not contain all hexadecimal digits.

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

ctype函数

总结

以上是生活随笔为你收集整理的ctype函数_PHP ctype_xdigit()函数与示例的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。