简体   繁体   English

数据来自哪里?

[英]Where is the data coming from?

It seems I met this problem before, in a different disguise. 看来我以前以另一种伪装遇到了这个问题。 When a file was being "included" in my main php file before starting a session in that same main php file, I'd get the "headers already sent" error because my included php had a blank line at the start, which was being somehow sent before anything should be sent. 当在同一主php文件中开始会话之前将文件“包含”在我的主php文件中时,我会收到“标头已发送”错误,因为我的包含的php在开始时有一个空行,这是以某种方式发送,然后再发送任何内容。 Delete blank line, "problem solved"... Now I have this ajax thingy where I scan a certain string returned by a php. 删除空白行,“问题已解决” ...现在我遇到了这个Ajax麻烦,我在其中扫描了php返回的某个字符串。 The string I hardcoded in this php to be returned to the ajax callback was the string "alert", which was never seen. 我在此php中硬编码要返回给ajax回调的字符串是字符串“ alert”,从未见过。 I scan what is being received by the callback, and guess what? 我扫描回调收到的内容,然后猜猜是什么? It has a character 10 starting my 5 character "alert" string. 它有一个从我的5个字符的“警报”字符串开始的字符10。

Sounds familiar? 听起来很熟悉? yes, I had an include before the "echo("alert");", and that include'd file DID start with a blank line (too! why I keep doing this???). 是的,我在“ echo(” alert“);”之前有一个include,并且那个include'd文件的DID以空行开头(太!为什么我继续这样做???)。 Delete line, and now I don't get the character 10 (ascii "new line" eh?) starting my "alert" string anymore. 删除行,现在我的“警报”字符串开始不再有字符10(ascii“换行”了吗?)。

The question: why is the php echo'ing a "new line" character that was never formally "echoed" along with my carefully crafted string? 问题:为什么php会回显一个从未被“回响”过的“新行”字符以及精心制作的字符串? Is this a bug of mine or php? 这是我的还是PHP的错误? Thanks in advance. 提前致谢。

Everything not inside your <?php ... ?> tags is treated as text and sent to the client. 不在<?php ... ?>标记内的所有内容均视为文本并发送给客户端。 So make sure not to have empty lines in your source files... 因此,请确保源文件中没有空行...

Edit: The purpose of this is to have a simple way to have a HTML file mixed with portions of PHP code without the need to echo all the HTML stuff explicitly... 编辑:这是为了有一个简单的方法来将HTML文件与部分PHP代码混合在一起,而无需显式地回显所有HTML内容...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM