就像我使用 PHP、MySQL、XML 和 JSON 创建基本 Web 服务所说明的那样,即使文件的扩展名以 PHP 结尾,您仍然可以告诉浏览器您正在输出不同的内容类型。以下是互联网上使用的一些较流行的内容类型。
原子
header('Content-Type: application/atom+xml');
CSS
header('Content-Type: text/css');
Javascript
header('Content-Type: text/javascript');
JPEG 图片
header('Content-Type: image/jpeg');
JSON
header('Content-Type: application/json');
header('Content-Type: application/pdf');
RSS
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
文本(纯文本)
header('Content-Type: text/plain');
XML
header('Content-Type: text/xml');
仅仅因为一个文件以 .PHP 结尾并不意味着它以 XHTML 响应——随您喜欢响应!