Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change mime type of output in php

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?

like image 521
Sam Avatar asked Sep 30 '08 06:09

Sam


People also ask

What are the different mime types?

A MIME type consists of two parts: a type and a subtype. Currently, there are ten registered types: application, audio, example, font, image, message, model, multipart, text, and video.

Why should mime type information be essentially included in HTTP responses?

MIME types enable browsers to recognize the filetype of a file which has been sent via HTTP by the webserver. As a result the browser is able to choose a suitable displaying method. Common MIME types are for example text/html for html-files or image/jpeg for jpeg-files.


2 Answers

header('Content-type: application/xml'); 

More information available at the PHP documentation for header()

like image 156
nickf Avatar answered Oct 11 '22 11:10

nickf


Set the Content-Type header:

header('Content-Type: text/xml'); 

Though you should probably use "application/xml" instead.

like image 20
John Millikin Avatar answered Oct 11 '22 10:10

John Millikin