Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 590
MKUltra Avatar asked Jan 22 '26 01:01

MKUltra


1 Answers

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.

like image 197
zombat Avatar answered Jan 25 '26 12:01

zombat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!