change mime type of output in php

Sam picture Sam · Sep 30, 2008 · Viewed 77.7k times · Source

I've got a php script. Most of the time the script returns html, which is working fine, but on one occasion (parameter ?Format=XML) the script returns XML instead of HTML.

Is there any way to change the returned mime type of the php output on the fly from text/html to text/xml or application/xml?

Answer

nickf picture nickf · Sep 30, 2008
header('Content-type: application/xml');

More information available at the PHP documentation for header()