开发者

Problem in UTF Encoding in PHP

开发者 https://www.devze.com 2023-02-09 03:58 出处:网络
I use the following lines of code: $revTerm =\"\". strrev($limitAry[\"term\"]); $revTerm = utf8_encode($revTerm);

I use the following lines of code:

$revTerm =  "". strrev($limitAry["term"]);
$revTerm = utf8_encode($revTerm);

The $revTerm contains Norwegian characters as ø æ å. However, it is shown correctly. I need to reverse them before displaying, so I use the first line. When I display them this way, I get an error of bad xml format - used to fill a grid. When I try to use the second line, I don't get an error but the characters are not shown correctly. Could th开发者_开发百科ere be any other way to solve that? If it may help, I use jqGrid to fill those data in.


strrev, like most PHP string functions, is not safe for multi-byte encodings.


try this example

$test = 'А роза упала на лапу Азора ウィキ';
$test = iconv('utf-8', 'utf-16le', $test);
$test = strrev($test);
// キィウ арозА упал ан алапу азор А
echo iconv('utf-16be', 'utf-8', $test);

(russian) http://bolknote.ru/2012/04/02/~3625#56


Try this:

$revTerm = utf8_decode($limitAry["term"]);
$revTerm = strrev($revTerm);
$revTerm = utf8_encode($revTerm);

For using strrev you have to decode your string to a non-multibyte string.

0

精彩评论

暂无评论...
验证码 换一张
取 消