PHP 26个英文字母递增

来源:互联网 发布:淘宝直播卖什么好 编辑:程序博客网 时间:2024/04/28 17:52
/** * 大写英文字母递增 *  * chr() 函数从指定的 ASCII 值返回字符 * ord() 函数返回字符串第一个字符的 ASCII 值 *  * @param string $str A-Z的英文字母 * @return string */function AZIncrement($str){    // 参数转换为大写    $str = strtoupper($str);    // 返回参数的 ASCII 值    $str = ord($str);        if ($str < 65 || $str > 90) {        // 参数不符合预期        return '你传过来的是什么鬼!';    }        if ($str == 90) {        // 参数已是末位英文字母Z,不可以递增        return '已经是 Z 啦!';    }        return chr($str+1);}echo AZIncrement(3);echo '<br />';echo AZIncrement('Z');echo '<br />';echo AZIncrement('b');echo '<br />';echo AZIncrement('h');


输出以下内容:

你传过来的是什么鬼!
已经是 Z 啦,不好再递增了!
C
I

0 0
原创粉丝点击