How to json_encode Chinese in PHP Back

In PHP, you'll find that when you call json_encode to encode Chinese, they will be converted into string like this \u4e2d\u6587.

After PHP 5.4, you can solve it by using JSON_UNESCAPED_UNICODE:

<?php
    echo json_encode('中文');   /** => "\u4e2d\u6587" */
?>
<?php
    echo json_encode('中文', JSON_UNESCAPED_UNICODE);   /** => "中文" */
?>
Empty Comments
Sign in GitHub

As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.

Notice: This plugin has used Cookie to store your token with an expiration.