Return to Snippet

Revision: 59953
at October 12, 2012 00:22 by iTony


Initial Code
<?php
function mb_strev ($string, $encoding = null) {
  if ($encoding === null) {
    $encoding = mb_detect_encoding($string);
  }

  $length = mb_strlen($string, $encoding);
  $reversed = '';
  while($length-- > 0) {
    $reversed .= mb_substring($string, $length, 1, $encoding);
  }

  return $reversed;
}

Initial URL
http://kvz.io/blog/2012/10/09/reverse-a-multibyte-string-in-php/

Initial Description
It is a bit simpler reversing of multibyte strings.

Initial Title
Reverse a multibyte string in PHP

Initial Tags
php

Initial Language
PHP