问题
I have been having issues with a newline appearing in my browser output with Codeigniter. What happens is I am outputting JSON data, but there is a newline character before any of the JSON data, and it is messing stuff up.
回答1:
Likely you have some whitespace at the end of one of your PHP files. It is a pretty common problem if you use the closing tag ?>
.
You'll want to search your code files and look for a ?>
with a newline character after it. Anything after a closing tag gets output to the browser.
As a habit, I don't use closing tags in code files for this reason, as they are not required by the PHP interpreter. Some coding standards recommend this as well. I only use them in template files where there is additional output between/after the PHP code.
来源:https://stackoverflow.com/questions/8607487/how-do-you-remove-a-leading-newline-in-output-to-browser-in-codeigniter