爪哇社区
  • 首页
  • 文章
  • 问答
  • 导航



  1. 首页
  2. 文章列表
  3. php怎么设置content-type

php怎么设置content-type

发布:HelloJq 时间:2024-10-20

PHP可以使用header()函数来设置Content-Type。通过设置Content-Type,可以告诉客户端正确解析服务器响应数据的方式。header()函数必须在输出任何内容之前调用,否则会导致错误。因此,建议在PHP文件开头就设置好Content-Type。

设置Content-Type为text/html:

header(“Content-Type: text/html; charset=utf-8”);

设置Content-Type为application/json:

 

header(“Content-Type: application/json”);

如果需要设置其他类型的Content-Type,可以在header()函数中通过调整MIME类型来实现。



爪哇社区 © 2024