Home  >  Article  >  Backend Development  >  strrev()反转中文字符串

strrev()反转中文字符串

WBOY
WBOYOriginal
2016-06-06 20:22:561427browse

如题,怎么处理中文字符串

回复内容:

如题,怎么处理中文字符串

php manual的strrev下面评论区有个函数
算是正则表达式的另类用法

<code>function utf8_strrev($str){
    preg_match_all('/./us', $str, $ar);
    return join('',array_reverse($ar[0]));
}</code>

把多字节字符串转化成UTF-32字符串,然后一个for循环自己反转,然后再转化成多字节字符串

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn