回声打破西里尔文符号

回声打破西里尔文符号

本文介绍了回声打破西里尔文符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的php脚本中向浏览器回显$ html变量(包含页面的html代码)。但是,如果我的$ html带有西里尔文符号,则该符号上的echo损坏-在此符号出现在页面上之前-其余所有元素均为空,

i want to echo $html variable (which contents html code of page) to browser in my php script. but if my $html has cyrillic symbol echo is breaking on it symbol - all before this symbol is on page - but all next is empty, what reason can it be?

推荐答案

$ html 的值的字符编码不适合用于声明输出的字符编码。您需要标识 $ html 的字符编码,并确保正确声明输出要用其编码。

The character encoding of the value of $html does not suit the character encoding you declare your output with. You need to identify the character encoding of $html and make sure to properly declare your output to be encoded with it.

做到这一点的最佳方法是:

The best way to do that is the HTTP header. You can do that with header:

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

此内容声明为使用UTF-8编码的HTML。

This declares the content to be HTML encoded with UTF-8.

此外,如果未指定其他字符,则PHP和Web服务器具有默认的字符编码。在PHP中,默认字符编码由;对于Apache Web服务器,由。

Besides that, PHP and the web server have default character encodings that are sent if no other was specified. In PHP, the default character encoding is specified by default_charset; and as for Apache web server, it is specified by AddDefaultCharset.

这篇关于回声打破西里尔文符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:40