How to reverse a Unicode string

后端 未结 6 1421
你的背包
你的背包 2020-12-06 17:04

It was hinted in a comment to an answer to this question that PHP can not reverse Unicode strings.

As for Unicode, it works in PHP because most app

6条回答
  •  清歌不尽
    2020-12-06 17:46

    The answer

    function mb_strrev($text, $encoding = null)
    {
        $funcParams = array($text);
        if ($encoding !== null)
            $funcParams[] = $encoding;
        $length = call_user_func_array('mb_strlen', $funcParams);
    
        $output = '';
        $funcParams = array($text, $length, 1);
        if ($encoding !== null)
            $funcParams[] = $encoding;
        while ($funcParams[1]--) {
             $output .= call_user_func_array('mb_substr', $funcParams);
        }
        return $output;
    }
    

提交回复
热议问题