1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- class Char{
- protected static $letters = array(
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
- "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
- );
-
- protected static $zhNums = array(
- "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十",
- );
-
- protected static $legal = array("UPPER", "LOWER");
- public static function numToLetter($num, $begain = 0, $case = "UPPER"){
- if(!in_array($case, self::$legal))
- trigger_error('param 3 must be one of "UPPER", "LOWER"');
-
- $num = (int)$num;
- $begain = (int)$begain;
-
- if(is_int($num) && is_int($begain) && $case){
- if($begain < 0) $begain = 0;
- $num = $num - $begain;
-
- if($num < 0) $num = 0;
- else if($num > 25) $num = 25;
-
-
- $letter = self::$letters[$num];
- if($case === "UPPER")
- $letter = strtoupper($letter);
-
- return $letter;
- }
-
- return $num;
- }
-
- public static function letterToNum($letter, $begain = 0){
- $letter = strtolower($letter);
- $rs = array_keys(self::$letters, $letter, true);
-
- if($rs)
- $position = current($rs) + $begain;
- else
- $position = null;
-
- return $position;
- }
-
- public static function numToZh($num){
- $len = count(self::$zhNums) - 1;
- $num = (int)$num;
-
- if($num < 0) $num = 0;
- if($num > $len) return null;
-
- return self::$zhNums[$num];
- }
- }
|