Welcome Guest, Not a member yet? Register   Sign In
2 trailing [EDIT:] leading whitespaces in output
#31

[eluser]mradlmaier[/eluser]
It gets even stranger:

Code:
echo substr($output, 2);

will result in in 2 white spaces only: ' '

Michael
#32

[eluser]Dam1an[/eluser]
Now that is REALLY strange, not to mention the fact this only seems to happen for you Confused
#33

[eluser]slowgary[/eluser]
I think Michael is a spy from CakePHP, sent to confuse us all with his fake problem while the rest of the team steals our flag. ;-P

Did you say you are hosting this local? Why not go setup some free hosting and try it elsewhere? Awardspace.com and Freehostia.com both offer free hosting with no ads. If you threw it up there where we can see it maybe there'd be a better chance of someone figuring it out. You could even share the FTP info and maybe we could each schedule and hour to tinker and see if we can solve the mystery. We'll turn it into a contest! First one to solve it gets bragging rights.
#34

[eluser]Dr. Seuss[/eluser]
Have you tried returning the view as data and then trimming?

$string = $this->load->view('myfile', '', true);
echo trim($string);

Won't "explain" the strangeness, but might solve the problem.

See the very bottom of this page:
http://ellislab.com/codeigniter/user-gui...views.html
#35

[eluser]Dam1an[/eluser]
I can't see doing it that way making a difference, as he's tried intercepting it at the very last moment possible before the rendered page is sent to the browser
#36

[eluser]TheFuzzy0ne[/eluser]
I think that until we can see some source code, it's one of those things that we can discuss until we are blue in the face, and still not find an answer to. Looking at the CodeIgniter source code, there's no way whatsoever that those spaces could be added, unless it's in the developer's code, or the developer has edited a source file.

I'd suggest a fresh copy of CodeIgniter, and if that doesn't work, then please zip up your application directory and post it.
#37

[eluser]mradlmaier[/eluser]
Hi All again,

As
Code:
echo trim($output);
produces 2 leading whitespace followed by 0 and
Code:
echo substr($output, 2);
produce 2 white spaces, i deduct that the 2 leading whitespaces are somehow inserted after $output is generated in Output.php.

Code:
$string = $this->load->view(‘myfile’, ‘’, true);
echo trim($string);

haven`t tried that yet, will try to see what happens later...
For now, using cURL to fetch the result with PHP and trimming that outside CI works as a workaround.

I hope, you all understand that i cannot post the complete source code (application folder) publicly here in this forum. A new copy of CI did not help, unfortunately. Some source code is posted above already.
In 2-3 month, the application will go live. If this problem persists on the remote host, i will post it here again, so you all can have a look.

Thanks to all for your responses,
Michael
#38

[eluser]joelrichard[/eluser]
I know this is a rather old thread, but it came up in my search and I, too, had the same problem. It took a bit of doing but I think I'm pretty sure I identified the source of the "leading whitespace" problem.

I had a helper (or a library or a plugin, I don't think that it matters) and there were two extra lines after the closing ?> in the PHP file. Eliminating those lines solved the problem.

So I replaced this

Code:
?>


(end of file)

With this

Code:
?>
(end of file)

And the newlines went away. It makes sense, too, as this helper code is called before any of the output code. It was also included by default on all my pages and so it was appearing elsewhere.

As a corollary to this if you have any spaces after your closing ?> they will also end up in your output. So for example "?> " would not be advisable.

In fact, if we go back to what someone said on a different thread then REMOVING the ?> from your files (all of them, if necessary) will help solve this problem in the future. All of the CI files use this technique. I think in mradlmaier's case, he must have had a helper (or similar) file that has whitespace at the end of the file.

Enjoy!
--Joel
#39

[eluser]meenxo[/eluser]
To contribute to this post just in case someone else is experiencing the same issue. As joelrichard has stated, the issue is with white spaces after closing a PHP tag. In my case, I had white spaces after the PHP closing tag in my MY_Contoller.php file (extended the CI_Controller).


I am not longer closing my PHP tags to avoid such issues, as recommended.




Theme © iAndrew 2016 - Forum software by © MyBB