如何从PHP告诉服务器charset是UTF-8 ?? [英] how to tell server from PHP that charset is UTF-8??

查看:75
本文介绍了如何从PHP告诉服务器charset是UTF-8 ??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让PHP告诉服务器当我将文本回显到

屏幕时,我需要将文本作为UTF-8发送?当PHP生成所有文本时,Apache如何知道

正确的编码?如果我建立一个内容管理系统(我有)并且我确保所有

输入编码为UTF-8,那么
$ b将如何$ b服务器知道MySql数据库中的文本是UTF-8吗?

我正在接受所有用户输入并在输入上使用此功能:

http://us4.php.net/ manual / en / function.utf8-encode.php


我这样做,所以我可以输出到XML而不会出现错误

你不应该发送纯文本。


但服务器如何知道如何提供这些页面?我如何从PHP中告知

?我意识到我可以发送一个http等效标签,但是这相当于很弱,对吧?


这够了吗?与Apache的任何冲突?


$ sent = headers_sent();

if(!$ sent)header(" Content-type:text / html; charset:UTF-8");

How do I get PHP to tell the server that when I echo text to the
screen, I need for the text to be sent as UTF-8? How does Apache know
the right encoding when all the text is being generated by PHP? If I
build a content management system (I have) and I make sure that all
input is encoded as UTF-8, how will the
server know that the text in the MySql database is UTF-8?

I''m taking all user input and using this function on the input:

http://us4.php.net/manual/en/function.utf8-encode.php

I''m doing this so I can output to XML without getting errors about
"You should not sent plain text".

But how will the server know how to serve these pages? How do I tell
it from PHP? I realize I can send a http equiv tag, but that''s rather
weak, right?

Is this enough? Any conflicts with Apache?

$sent = headers_sent();
if (!$sent) header("Content-type:text/html;charset:UTF-8");

推荐答案

sent = headers_sent();

if(!
sent = headers_sent();
if (!


已发送)标题(Content-type:text / html; charset:UTF-8);
sent) header("Content-type:text/html;charset:UTF-8");


2004年9月4日09: 08:41-0700, lk******@geocities.com (lawrence)写道:
On 4 Sep 2004 09:08:41 -0700, lk******@geocities.com (lawrence) wrote:
如何让PHP告诉服务器当我将文本回显到
屏幕时,我需要将文本作为UTF-8发送?


发送带有charset属性的内容类型标头。

当所有文本生成时,Apache如何知道正确的编码PHP?


它不是,也不需要 - 这些信息仅供最终用户使用。

如果我构建
一个内容管理系统(我有),我确保所有
输入编码为UTF-8,
服务器如何知道MySql数据库中的文本是UTF-8?

我正在接受所有用户输入并在输入上使用此功能:

http://us4.php.net/manual/en/function.utf8-encode.php

我正在这样做,所以我可以输出到XML而不会出现错误
你不应该发送纯文本。


我不知道你的意思。 XML内容不必是UTF-8编码,

只是正确转义并且编码设置正确。

但服务器如何知道如何提供这些页面?我如何用PHP告诉它?我意识到我可以发送一个http等效标签,但这相当弱,对吧?


是的。

这够了吗?与Apache的任何冲突?

How do I get PHP to tell the server that when I echo text to the
screen, I need for the text to be sent as UTF-8?
Sent a content-type header with a charset attribute.
How does Apache know
the right encoding when all the text is being generated by PHP?
It doesn''t, nor does it need to - that information''s just for the end user.
If I
build a content management system (I have) and I make sure that all
input is encoded as UTF-8, how will the
server know that the text in the MySql database is UTF-8?

I''m taking all user input and using this function on the input:

http://us4.php.net/manual/en/function.utf8-encode.php

I''m doing this so I can output to XML without getting errors about
"You should not sent plain text".
Don''t know what you mean here. XML content doesn''t have to be UTF-8 encoded,
just properly escaped and the encoding set correctly.
But how will the server know how to serve these pages? How do I tell
it from PHP? I realize I can send a http equiv tag, but that''s rather
weak, right?
Yep.
Is this enough? Any conflicts with Apache?


这篇关于如何从PHP告诉服务器charset是UTF-8 ??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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