Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5286 Lượt xem

I'm retrieving from Odoo 9 on Ubuntu 14.04 ENG a list of partners via XML-RPC using PHP and ripcord.

Some names contain one or more diacritics:

  • Pièr

  • Frère Pièr

All those names have been entered from a single computer running Windows 8.1 using one version of Chrome.

The strange fact is that I get a list where some diacritics are correct, some other have encoding problems, like:

  • Pi�r

  • Fr�re Pièr

The same diacritic in the same string is correctly encoded or not.

In subsequent calls the result is always the same.

If I edit the string, then it could change the results, giving 

  • Frère Pi�r

  • Frère Pièr

  • Fr�re Pi�r...

I need to output a JSON, and thus I need to encode this in UTF-8: but it is currently impossible since I don't have a clue of what encoding the original text is (and it seems to not have any encoding at all!)

Any idea?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I found out that the incoming array was in charset "Latin1"

I solved normalizing the array generated from the XML-RPC output, recursively applying a multbyte conversion function:

// given an XML-RPC output named $arr_output...

function descramble_diacritics(&$entry, $key) {
$entry = mb_convert_encoding($entry, 'UTF-8', 'Latin1');
}
array_walk_recursive($arr_output, 'descramble_diacritics');

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
echo json_encode($arr_output);


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
6274
3
thg 1 23
8659
1
thg 3 22
6104
1
thg 2 22
6168
1
thg 9 20
7738