How can the Content-Type header be set to ensure proper XML viewing in a web browser when serving XML content from a PHP application?
When serving XML content from a PHP application, it is important to set the Content-Type header to "application/xml" or "text/xml" to ensure proper XML viewing in a web browser. This header informs the browser how to interpret the content being served, allowing it to display the XML data correctly.
header('Content-Type: application/xml');
// or
header('Content-Type: text/xml');
// Output your XML content here
echo '<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>Content goes here</element>
</root>';