How can UTF-8 encoding be ensured for JSON data in PHP applications?
When working with JSON data in PHP applications, it's important to ensure that the data is encoded in UTF-8 to support international characters. To achieve this, you can use the `json_encode` function with the `JSON_UNESCAPED_UNICODE` option to prevent the encoding of Unicode characters.
$data = array('name' => 'John Doe', 'city' => '東京');
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
echo $json;
Keywords
Related Questions
- What are some best practices for creating a program to generate a schedule for a sports event using PHP?
- How can you effectively paginate a long table in PHP to display a limited number of rows per page?
- How can PHP be used to extract formatting information from text files, such as .doc or .txt files?