PHP
·
发表于 5年以前
·
阅读量:8303
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¡£