Home / PHP Tips Generated By ChatGPT / Using header() to Set Content Type in PHP Specify the content type of the output with the header() function, useful for APIs or serving different types of content. Source Code header('Content-Type: application/json'); echo json_encode(['message' => 'Hello, World!']);