Empty line in PHP (CodeIgniter) file download Empty line in PHP (CodeIgniter) file download codeigniter codeigniter

Empty line in PHP (CodeIgniter) file download


If $contents in your function does not have a newline, try using the output buffer functions.

At the beginning of your file, before including any other files, call ob_start();. Then, inside your function, before echo $contents;, add ob_end_clean();. This will make sure none of the output from other scripts is sent.


Vi editor (or vim) leaves an extra newline at the end of edited file. If you have used vi for any included file, that must be the issue.

Following answer describes removing newlines at the end of files in an easy way:

How can I delete a newline if it is the last character in a file?

Given command can be used together with linux find to remove all trailing newlines in php files.

for i in `find /path/to/project -name *.php`do    perl -i -pe 'chomp if eof' $idone


I did not understand your problem exactly, but since your $content is a string, You can simply use

echo trim($content)

To remove the new lines