- URL: https://www.laruence.com/en/2011/10/10/2239.html
- Please include attribution when republishing.
We know that when using PHP's json_encode to handle Chinese, the Chinese is all encoded, turned into an unreadable format like "\u***", and it also increases the amount of data transmitted to some extent.
<?php
echo json_encode("中文");
//"\u4e2d\u6587"
This gives us developers in China a real headache, and sometimes we even have to write json_encode ourselves.
But in PHP 5.4, this problem is finally solved. Json added a new option: JSON_UNESCAPED_UNICODE. As the name suggests, it means: don't let Json encode Unicode.
Look at the example below:
<?php
echo json_encode("中文", JSON_UNESCAPED_UNICODE);
//"中文"
Well, is that a change that makes everyone happy? Hehe. Of course, in 5.4 Json also added options like JSON_BIGINT_AS_STRING, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, etc. If you're interested, you can refer to: json_encode
That said, a reminder: PHP 5.4 is still under development. Before the final release, any new feature may be adjusted or changed. If you have any suggestions, feedback is welcome, to help make PHP even better.
Thanks
For more updates, follow: Changelog
Be First to Comment