找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 63|回复: 0
打印 上一主题 下一主题

PHP中文竖排转换实现方法

[复制链接]

2617

主题

2617

帖子

7789

积分

论坛元老

Rank: 8Rank: 8

积分
7789
跳转到指定楼层
楼主
发表于 2018-2-14 05:42:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            PHP中文竖排转换程序,文本框输入文字,转换后会竖排文字。
效果图

index.php内容

convert($_POST['string']);
}
?>









ccw.inc.php文件内容:
'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 CHARLIST[$c]) ? $this->CHARLIST[$c] : $c;
if (sizeof($tmp) == $height) {
$result[] = $tmp;
$tmp = array();
}
}

// 如果还有剩余的字符
if (sizeof($tmp)) {
$result[] = $tmp;
}

// 开始输出
$output = "";
for($j = 0; $j = 0; $i--) {
$output .= $this->SEPARATOR;
$output .= isset($result[$i][$j]) ? $result[$i][$j] : $this->BLANK;
}
$output .= $this->SEPARATOR;
$output .= "\n";
}

return $output."";
}


/**
* 转换字符串至数组
*/
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中文竖排转换的实现方法,希望对大家的学习有所帮助。
            
            
您可能感兴趣的文章:
  • PHP 中英文混合排版中处理字符串常用的函数
  • 解析php利用正则表达式解决采集内容排版的问题
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端