手机版

PHP中文竖排转换实现方法

时间:2021-09-29 来源:互联网 编辑:宝哥软件园 浏览:

服务器端编程语言(专业超文本预处理器的缩写)中文竖排转换程序,文本框输入文字,转换后会竖排文字。

效果图

index.php内容

?PHP包含(' 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' /格式方法='post '字符集='utf-8' p?php echo $converd?/p ptextarea name=' string ' cols=' 50 ' row=' 10 '/textarea/p pinput type=' submit '/p/form ccw.inc.php文件内容:

?php /** *转换中文字符串至古文排版通道命令字(channel command word的缩写)类{受保护的$分隔符='';受保护的$ BLANK=受保护的$CHARLIST=数组(' 0'='0 ',' 1'='1 ',' 2'='2 ',' 3'='3 ',' 4'='4 ',' 5'='5 ',' 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'=' 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 ',' E'='E ',' F'='F ',' G'='G ',' H'='H ',' I'='I ',' J ',' Q '='Q ',' R'='R ',' S'='S ',' T'='T ',' U'='U ',' v ',' w ',' X'='X ',' y '=' z ','('='︵' ')='︶','['='︻',']'='︼',' { '='︷',}'='︸','=' '︽','='︾' ',' *=' * ',='& ','=' 08 ',' %=' % ' % ','='!' , '~'='~', '`'='`', ' '=' ', '-'='-', '='='=', '_'='_', '|'='|', '\\'='\', '\''=''', '''='"', ';'=';', ':'=':', '.'='.', ','=',', '?'='?', '/'='/', ' '=' ', '('='︵', ')'='︶', '【'='︻', '】'='︼', ' 《' = '︽', '》 '='︾' );公共$ height=10//默认竖排高度/** * 转换文字到竖排* * @ return string */function convert($ origin,$ height=null){ $ origin=preg _ replace('/\ s/','',$ origin);//去除多余的空格等$ strarr=$ this-MBStringToaray($ original);//分解成数组$身高=$身高?intval(高度):美元这个高度;$ total=sizeof($ strarr);$ width=ceil($ total/$ height);//分割中文字符$ result=array();for ($i=0,$ tmp=array();一美元总计;$ 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=' preformer($ j=0;$ j $高度;$ j){ for($ I=$ width-1;$ I=0;$i - ) { $output .=$ this-SEPARATOR;$输出=isset($result[$i][$j])?$ result[$ I][$ j]: $ this-BLANK;} $输出=$ this-SEPARATOR;$输出=' \ n}返回产出./pre ';} /** * 转换字符串至数组*/私有函数MBStringToaray($ string,$ encoding=' utf-8 '){ while($ strlen=MB _ strlen($ string)){ $ array[]=MB _ substr($ string,0,1,$ encoding);$string=mb_substr($string,1,$strlen,$ encoding);}返回$ array} }?以上就是服务器端编程语言(专业超文本预处理器的缩写)中文竖排转换的实现方法,希望对大家的学习有所帮助。

版权声明:PHP中文竖排转换实现方法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。