如何为 PHP 文件设置 UTF-8 编码 [英] How to set UTF-8 encoding for a PHP file

查看:41
本文介绍了如何为 PHP 文件设置 UTF-8 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 :

http://cyber-flick.com/apiMorpho.php?method=getMorphoData&word=kot

以纯文本形式显示一些数据:

That displays some data in plain text:

Cz��� mowy: rzeczownik
Przypadek: dope�niacz
Rodzaj: şe�ski
Liczba: mnoga

正如你所看到的,在适当的字符处有很多灌木丛".我想要做的是以一种方式显示它,以便人们在浏览器中看到正确的 UTF-8 字符.

As you can see in place of proper chars there are so "bushes". What i would like to do is display this in a way so that people see in browser proper UTF-8 characters.

你可以把它封装在HMTL标签中并设置成meta UTF-8编码,但是因为从这个脚本接收到的数据会被进一步处理我不想使用任何HTML标签,它应该只是纯文本结果集.

You can encapsulate it in HMTL tags and set in meta UTF-8 encoding, but because the data received from this script will be processed further I don't want to use any HTML tags, it should be only plain text result set.

那么有没有办法在不使用元标记的情况下通知浏览器这个文件是UTF-8?

So is there a way to inform browser that this file is UTF-8 without using meta tags?

附注.文件以 UTF-8 编码,如果我手动将浏览器中的字符集编码更改为 UTF-8,它显示正常,但我想要完成的是人们不需要这样做.

PS. File is encoded in UTF-8 and if I manually change charset encoding in my browser to UTF-8 it displays ok, but what I want to acomplish is people to not be required to do so.

推荐答案

header('Content-type: text/plain; charset=utf-8');

这篇关于如何为 PHP 文件设置 UTF-8 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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