是header('Content-Type:text/plain');有必要吗? [英] Is header('Content-Type:text/plain'); necessary at all?

查看:801
本文介绍了是header('Content-Type:text/plain');有必要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论有没有这个主要信息,我都没有看到任何区别.

I didn't see any difference with or without this head information yet.

推荐答案

定义必需".

如果您希望浏览器 知道 ,则文件类型是必要的.如果不覆盖,则PHP会自动将Content-Type标头设置为text/html,因此浏览器会将其视为不包含任何HTML的HTML文件.如果您的输出包含任何HTML,您将看到截然不同的结果.如果您要发送:

It is necessary if you want the browser to know what the type of the file is. PHP automatically sets the Content-Type header to text/html if you don't override it so your browser is treating it as an HTML file that doesn't contain any HTML. If your output contained any HTML you'd see very different outcomes. If you were to send:

<b><i>test</i></b>

a Content-Type: text/html将输出:

测试

test

Content-Type: text/plain会输出:

<b><i>test</i></b>

TLDR版本::如果您确实只输出文本,则没关系,但是 IS 错误.

TLDR Version: If you really are only outputing text then it doesn't really matter, but it IS wrong.

这篇关于是header('Content-Type:text/plain');有必要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆