How to reverse a Unicode string

后端 未结 6 1406
你的背包
你的背包 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:35

    Here's another way. This seems to work without having to specify an output encoding (tested with a couple of different mb_internal_encodings):

    function mb_strrev($text)
    {
        return join('', array_reverse(
            preg_split('~~u', $text, -1, PREG_SPLIT_NO_EMPTY)
        ));
    }

提交回复
热议问题