PHPÖÐÎÄÊúÅÅת»»ÊµÏÖ·½·¨

5年以前  |  阅读数:511 次  |  编程语言:PHP 

PHPÖÐÎÄÊuÅÅת»»³ÌÐo£¬Îı¾¿oÊaÈeÎÄ×Ö£¬×ª»»ºo»aÊuÅÅÎÄ×Ö¡£

Ч¹uͼ

index.phpÄÚÈÝ


    <?php 
    include('ccw.inc.php'); 

    if (isset($_POST['string'])){ 
     $ccw = new CCW; 
     $converd = $ccw->convert($_POST['string']); 
    } 
    ?> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <form method="post" charset="utf-8"> 
     <p><?php echo $converd ?></p> 
     <p><textarea name="string" cols="50" rows="10"></textarea></p> 
     <p><input type="submit" /></p> 
    </form> 

ccw.inc.phpÎļþÄÚÈÝ£º


    <?php 
    /** 
     * ת»»ÖÐÎÄ×Ö*u´®ÖÁ¹ÅÎÄÅÅ°ae 
     */ 
    class CCW { 
     protected $SEPARATOR = '(C)ª'; 
     protected $BLANK = '¡¡'; 
     protected $CHARLIST = array( 
     '0' => '£°', '1' => '£±', '2' => '£²', '3' => '£³', '4' => '£´', '5' => '£µ', 
     '6' => '£¶', '7' => '£*', '8' => '£¸', '9' => '£¹', 'a' => '£a', 'b' => '£a', 
     'c' => '£a', 'd' => '£a', 'e' => '£a', 'f' => '£ae', 'g' => '£ç', 'h' => '£e', 
     'i' => '£e', 'j' => '£e', 'k' => '£e', 'l' => '£i', 'm' => '£i', 'n' => '£i', 
     'o' => '£i', 'p' => '£ð', 'q' => '£ñ', 'r' => '£o', 's' => '£o', 't' => '£o', 
     'u' => '£o', 'v' => '£o', 'w' => '£÷', 'x' => '£ø', 'y' => '£u', 'z' => '£u', 
     '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' => '£Ú', '(' => '¦a', ')' => '¦a', '[' => '¦i', ']' => '¦i', 
     '{' => '¦ð', '}' => '¦ñ', '<' => '¦ae', '>' => '¦ç', '*' => '£ª', '&' => '£¦', 
     '^' => '¦a', '%' => '£¥', '$' => '¡ç', '#' => '££', '@' => '£À', '!' => '£¡', 
     '~' => '¡«', '`' => '£a', '+' => '£«', '-' => '£­', '=' => '£½', '_' => '£ß', 
     '|' => '£u', '\\' =>'£Ü', '\'' =>'£§', '"' => '£¢', ';' => '£»', ':' => '£º', 
     '.' => '£®', ',' => '£¬', '?' => '£¿', '/' => '£¯', ' ' => '¡¡', '£¨' => '¦a', 
     '£(C)' => '¦a', '¡¾' => '¦i', '¡¿' => '¦i', '¡¶' => '¦ae', '¡*' => '¦ç' 
     ); 

     public $height = 10; // ĬÈÏÊuÅÅ¸ß¶È 

     /** 
     * ת»»ÎÄ×Öµ½ÊuÅÅ 
     * 
     * @return string 
     */ 
     function convert($original, $height = null) { 
     $original = preg_replace('/\s/', '', $original); // È¥³ý¶aÓaµÄ¿Õ¸ñµÈ 
     $strarr = $this->mbStringToArray($original); // *Ö½a³ÉÊý×e 
     $height = $height ? intval($height) : $this->height; 
     $total = sizeof($strarr); 
     $width = ceil($total / $height); 

     // *Ö¸iÖÐÎÄ×Ö*u 
     $result = array(); 
     for ($i = 0, $tmp = array(); $i < $total; $i++) { 
     $c = $strarr[$i]; // ¸ñʽ»¯µ±Ç°×Ö*u 
     $tmp[] = isset($this->CHARLIST[$c]) ? $this->CHARLIST[$c] : $c; 
     if (sizeof($tmp) == $height) { 
     $result[] = $tmp; 
     $tmp = array(); 
     } 
     } 

     // Èç¹u»¹ÓÐÊ£ÓaµÄ×Ö*u 
     if (sizeof($tmp)) { 
     $result[] = $tmp; 
     } 

     // ¿ªÊ¼Êa³o 
     $output = "<pre>"; 
     for($j = 0; $j < $height; $j++) { 
     for ($i = $width - 1; $i >= 0; $i--) { 
     $output .= $this->SEPARATOR; 
     $output .= isset($result[$i][$j]) ? $result[$i][$j] : $this->BLANK; 
     } 
     $output .= $this->SEPARATOR; 
     $output .= "\n"; 
     } 

     return $output."</pre>"; 
     } 


     /** 
     * ת»»×Ö*u´®ÖÁÊý×e 
     */ 
     private function mbStringToArray ($string, $encoding = 'utf-8') { 
     while ($strlen = mb_strlen($string)) { 
     $array[] = mb_substr($string, 0, 1, $encoding); 
     $string = mb_substr($string, 1, $strlen, $encoding); 
     } 

     return $array; 
     } 
    } 
    ?> 

ÒÔÉϾÍÊÇphpÖÐÎÄÊuÅÅת»»µÄʵÏÖ½¨£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例