echo
if(!ctype_alnum($vipurl)){
echo '只能是字母或数字的组合';exit;}
顺便复习下ctype functions
1.ctype_alnum(string $text)://检查是否是字母或数字或字母数字的 组合
2.ctype_alpha(string $text):check for alphabetic character(s) //检查字符串是否是字母
3.ctype_cntrl(string $text):check for control character(s) //是否是控制字符如 , ,\t
4.ctype_digit(strint $text):check for numeric character(s) //是否是数字表示的字符大多数时也许应该用is_numeric
这个要特别注意与is_numeric()的区别
例:$numeric_string='42';
$interger = 42;
ctype_digit($numeric_string);//true
ctype_digit($interger);//false
is_numeric($numeric_string); //true
is_numeric($interger); //true
5.ctype_graph(string $text):Check for any printable character(s) except space
6.ctype_lower():check for lowercase character(s)//检查是否是小写字母
7.ctype_upper():check for uppercase character(s)//检查是否是大写字母
8.ctype_space: check for whitespace character(s)//是否是空白字符
9.ctype_xdigit: check for character(s) representing a hexadecimal digit//检查是否是十六进制数字
实例: if((!isset($error)) and (!preg_match(/^[_0-9a-zA-Z]{3,12}$/i,$nicker))) $error='只能是英文字母或数字, 且长度必须是3-12个字';
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
ctype_alnum — 做字母和数字字符检测
$strings = array('AbCd1zyZ9', 'foo!#$bar');
foreach ($strings as $testcase) {
if (ctype_alnum($testcase)) {
echo "The string $testcase consists of all letters or digits.\n";
} else {
echo "The string $testcase does not consist of all letters or digits.\n";
}
}
?>
结果如下:
The string AbCd1zyZ9 consists of all letters or digits.
The string foo!#$bar does not consist of all letters or digits.
文档地址:
http://www.php.net/manual/zh/function.ctype-alnum.php