您的位置:首页 > 编程语言 > PHP开发

php中技巧注意笔记2

2013-07-01 17:25 127 查看
PHP5中,有个新的验证方法,CTYPE,可以专门针对字符串进行验证



<?php

    if (!ctype_alnum($_GET['login'])) {

       echo "输入项必须为英文字符或数字0-9。";

    }

    if (!ctype_alpha($_GET['captcha'])) {

       echo "输入项必须为英文字符(大小写均可)";

    }

    if (!ctype_xdigit($_GET['color'])) {

       echo "输入项必须填写一个16进制数字。";

    }

?>

还有检查大小写的

<?php

$strings = array('aac123', 'qiutoas', 'QASsdks');

foreach ($strings as $testcase) {

    if (ctype_lower($testcase)) {

        echo "The string $testcase consists of all lowercase letters.\n";

    } else {

        echo "The string $testcase does not consist of all lowercase letters.\n";

    }

}

?>


检查空白字符的

<?php

$strings = array('string1' => "\n\r\t", 'string2' => "\narf12", 'string3' => '\n\r\t');

foreach ($strings as $name => $testcase) {

    if (ctype_space($testcase)) {

        echo "The string '$name' consists of all whitespace characters.\n";

    } else {

        echo "The string '$name' does not consist of all whitespace characters.\n";

    }

}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: