📅  最后修改于: 2023-12-03 15:02:08.939000             🧑  作者: Mango
JSON header in PHP is a technique used to send response headers in JSON format instead of traditional HTML or plain text format. This technique is widely used in modern web applications to retrieve data from external APIs and display the JSON response on the web page.
Following is a simple code snippet that demonstrates how to send a JSON header in PHP.
header('Content-Type: application/json');
echo json_encode($data);
In the code snippet, we first set the content type header to application/json
using the header()
function. Then, we encode the data in JSON format using the json_encode()
function and send the response using the echo
statement.
JSON header in PHP is a powerful technique for retrieving data from external APIs and displaying JSON responses on web pages. This technique is easy to implement and provides a lightweight, efficient way to communicate between web applications and external APIs.