php vs txt 显示 - 快递和时间
为什么当我将纯文本文件上传到服务器时,它(在 Safari 中)使用 courier 字体显示,而当我从 php 输出时,它显示为 Times?
Why is it when I upload a plain text file to a server, it displays (in Safari) using the courier font, and when I output from a php it shows as Times?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
纯文本就是纯文本。它本身不携带格式信息,浏览器将决定如何显示它。直接显示文件时,Web 服务器将为其提供 mime 类型
text/plain
。这通常会指示浏览器使用固定宽度字体(Courier)。但是,如果您使用 PHP 输出它,服务器会将其作为text/html
(HTML) 发送,并且浏览器将使用 HTML 的默认字体(在您的情况下为 Times)。对于纯文本,您无法控制最终用户的浏览器如何呈现它。该设置完全取决于浏览器默认值或用户首选项。当然,您可以通过 PHP 和 CSS 声明来影响它如何显示为 HTML。
Plain text is plain text. It carries no formatting information of its own, and the browsers will decide how to display it. Displaying a file directly, the web server will supply it with a mime type
text/plain
. This will often instruct the browser to use a fixed width font (Courier). But if you output it with PHP, the server is sending it astext/html
(HTML) and the browser is using its default font for HTML (Times, in your case).For the plain text, you don't have any control over how the end user's browser will render it. That setting is entirely up to browser defaults or user preferences. Of course, you can influence how it is displayed as HTML when output by PHP with CSS declarations.
这是因为
Content-type
HTTP 标头。对于 txt 文件,它是
text/plain
;对于 phpWeb 服务器,它是
text/html
,检查文件的 mime 类型(通过扩展名判断)并发送适当的标头。That's because of
Content-type
HTTP header.It's
text/plain
in case of txt file andtext/html
with phpWeb-server do check mime-type of the file (judging by extension) and send appropriate header.
这是由您的浏览器指定的。如果您喜欢其他字体,可以在浏览器设置中进行设置。你所描述的是一个常见的设置。
服务器仅指定所谓的内容类型,文本文件的
text/plain
, php 页面的text/html
。用户使用浏览器来相应地显示它们,例如字体及其大小。如果您将 CSS 添加到 html 输出中,并且用户允许您的网站提供 CSS 用于显示目的(这也很常见),那么将使用 CSS 样式信息,这可能会更改字体和大小。
That's specified by your browser. You can setup that within your browsers settings if you prefer other fonts. What you describe is a common setup.
The server is only specifying the so called content-type,
text/plain
for the text-file,text/html
for the php page.The user uses the browser to display them accordingly, like the font and it's size. If you add CSS to your html output and the user allows your website to provide CSS for displaying purposes (which is quite common as well), then the CSS style information will be used which could change the font and size.