简体   繁体   中英

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. Delete blank line, "problem solved"... Now I have this ajax thingy where I scan a certain string returned by a php. The string I hardcoded in this php to be returned to the ajax callback was the string "alert", which was never seen. I scan what is being received by the callback, and guess what? It has a character 10 starting my 5 character "alert" string.

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???). Delete line, and now I don't get the character 10 (ascii "new line" eh?) starting my "alert" string anymore.

The question: why is the php echo'ing a "new line" character that was never formally "echoed" along with my carefully crafted string? Is this a bug of mine or php? Thanks in advance.

Everything not inside your <?php ... ?> tags is treated as text and sent to the client. 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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