您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 延边分类信息网,免费分类信息发布

PHP中文竖排转换程序

2024/4/17 14:04:06发布8次查看
本篇文章主要介绍php中文竖排转换程序,感兴趣的朋友参考下,希望对大家有所帮助。
效果图
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 /** * 转换中文字符串至古文排版 */ class ccw { protected $separator = '┆'; protected $blank = ' '; protected $charlist = array( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd', 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i', 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n', 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z', '(' => '︵', ')' => '︶', '[' => '︻', ']' => '︼', '{' => '︷', '}' => '︸', '<' => '︽', '>' => '︾', '*' => '*', '&' => '&', '^' => '︿', '%' => '%', '$' => '$', '#' => '#', '@' => '@', '!' => '!', '~' => '~', '`' => '`', '+' => '+', '-' => '-', '=' => '=', '_' => '_', '|' => '|', '\\' =>'\', '\'' =>''', '"' => '"', ';' => ';', ':' => ':', '.' => '.', ',' => ',', '?' => '?', '/' => '/', ' ' => ' ', '(' => '︵', ')' => '︶', '【' => '︻', '】' => '︼', '《' => '︽', '》' => '︾' ); public $height = 10; // 默认竖排高度 /** * 转换文字到竖排 * * @return string */ function convert($original, $height = null) { $original = preg_replace('/\s/', '', $original); // 去除多余的空格等 $strarr = $this->mbstringtoarray($original); // 分解成数组 $height = $height ? intval($height) : $this->height; $total = sizeof($strarr); $width = ceil($total / $height); // 分割中文字符 $result = array(); for ($i = 0, $tmp = array(); $i < $total; $i++) { $c = $strarr[$i]; // 格式化当前字符 $tmp[] = isset($this->charlist[$c]) ? $this->charlist[$c] : $c; if (sizeof($tmp) == $height) { $result[] = $tmp; $tmp = array(); } } // 如果还有剩余的字符 if (sizeof($tmp)) { $result[] = $tmp; } // 开始输出 $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>"; } /** * 转换字符串至数组 */ 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使用number_format函数截取小数的方法及实例分析
php使用pdo连接sqlite3的配置方法详解
php实现通过文件头判断格式的方法
以上就是php中文竖排转换程序的详细内容。
延边分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录