How do you remove a leading newline in output to browser in Codeigniter

跟風遠走 提交于 2019-12-22 10:45:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!