0
<?php
header("Content-type: text/csv; charset=GB2312");
$arr = array('丂','亐');
echo json_encode($arr);
?>

Instead providing chinese character array, json_encode return null values.

Wasim A.
  • 9,660
  • 22
  • 90
  • 120

1 Answers1

3

json_encode works with UTF-8 encoded strings only. If you need to create valid json successfully from an Chinese encoded string, you need to re-encode/convert it to UTF-8 first. Then json_encode will just work as documented.

Use iconv for converting encoding, you can also use mb_convert_encoding

$str = iconv("GB2312", "UTF-8", $str);
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100