PHP包含输出未知字符的函数 [英] PHP Include function outputting unknown char

查看:183
本文介绍了PHP包含输出未知字符的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用php include函数时,include被成功执行,但是在输出include的输出之前也输出一个char,char是十六进制值3F,我不知道它来自哪里,尽管似乎每个包含都会发生。

When using the php include function the include is succesfully executed, but it is also outputting a char before the output of the include is outputted, the char is of hex value 3F and I have no idea where it is coming from, although it seems to happen with every include.

起初我打了它的文件编码,但这似乎不是一个问题。我创建了一个测试用例来证明:(链接不再工作 http:/ /driveefficiently.com/testinclude.php ,该文件仅包含:

At first I thbought it was file encoding, but this doesn't seem to be a problem. I have created a test case to demonstrate it: (link no longer working) http://driveefficiently.com/testinclude.php this file consists of only:

<? include("include.inc"); ?>

和include.inc只包含:

and include.inc consists of only:

<? echo ("hello, world"); ?> 

然而,输出是:?hello,world其中的?是一个随机值的char。正是这个价值,我不知道它的起源,有时会把我的网站搞砸。

and yet, the output is: "?hello, world" where the ? is a char with a random value. It is this value that I do not know the origins of and it is sometimes screwing up my sites a bit.

有什么想法可以来自哪里?起初我以为可能与文件编码有关,但我不认为它是一个问题。

Any ideas of where this could be coming from? At first I thought it might be something to do with file encoding, but I don't think its a problem.

推荐答案

什么你看到的是一个UTF-8字节顺序标记:

What you are seeing is a UTF-8 Byte Order Mark:


BOM的UTF-8表示是字节序列EF BB BF,在大多数文本编辑器和Web浏览器中都没有准备好处理UTF-8的情况下,它显示为ISO-8859-1字符。

The UTF-8 representation of the BOM is the byte sequence EF BB BF, which appears as the ISO-8859-1 characters  in most text editors and web browsers not prepared to handle UTF-8.

维基百科上的字幕订单标记

PHP不明白这些字符应该是隐藏的,并将它们发送到浏览器,就像它们是正常字符一样。要摆脱它们,您将需要使用正确文本编辑器打开该文件,这将允许您将文件保存为UTF-8,而不带领导BOM。

PHP does not understand that these characters should be "hidden" and sends these to the browser as if they were normal characters. To get rid of them you will need to open the file using a "proper" text editor that will allow you to save the file as UTF-8 without the leading BOM.

您可以在这里阅读有关此问题的更多信息

这篇关于PHP包含输出未知字符的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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