Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of Chinese garbled codes in gbk and gb2312 handled by json_encode in php

Shulou Source: shulou.com Published: 2022-06-03 18:51:35 11月12日 Update

The content of this article mainly explains "how to solve the Chinese garbled code of json_encode in php dealing with gbk and gb2312". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to solve the Chinese garbled code of gbk and gb2312 in json_encode in php"!

This paper describes the solution of json_encode in php to deal with the problem of garbled codes in gbk and gb2312. The specific methods are as follows:

1.json_encode () Chinese is returned as null for Chinese in gbk/gb2312

$arr = array (array ('catid' = >' 44th, 'catname' = >' www.jb51.net', 'meta_title' = >''); echo json_encode ($arr)

Running result:

[{"catid": "4", "catname": "www.jb51.net", "meta_title": null}]

Have you seen "meta_title": null, he used to have a value of "". We checked that the principle is that json_encode only supports uft-8 encoding. Let's convert it.

Tags: Chinese character processing garbled string result function method coding output content page UTF-8 learning practical deeper bad interest method principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi NVidia OPPO Reno macOS