shahrzad khorrami wrote:
hi all,

for reversing of characters, strrev() is good. but for persian characters
it doesn't work!

Thanks

How nice of you to let us know! Now, is there a question in here somewhere? or is that all you wanted to say?

--
_assuming_ you want to know why this is:
Persian characters are represented using > 1 byte per character. strrev() assumes exactly 1 byte per character, and just reverses the "string" of bytes. Which results in a reversed string. (some) Persian characters are represented using 2 (or more?) bytes; just reversing those will lead to an entirely different chracter (or comination thereof).
_assuming_ you want to know how to get around this:
Use a function which handles these cases properly. One that is encoding-aware (and doesn't just assume a 1-byte charset). You can either use a combination of iconv_* functions to do this, or use a combination of mb_* functions.
Something like this should work:
function iconv_strrev($string, $encoding) {
   $return = '';
   $len = iconv_strlen($string, $encoding);
   for($i=($len-1);$i >= 0;$i--) {
      $return .= iconv_substr($string, $i, 1, $encoding);
   }
   return $return;
}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to