Welcome Guest, Not a member yet? Register   Sign In
An odd quirk with RSS
#1

[eluser]joncarl[/eluser]
Hello all!

I've read a few topics on the extra whitespace that people have gotten that bugs their rss feed. I ran into the same issue when following Derek Allard's excellent tutorial on setting up an RSS feed. So I started to pick apart my code and kept getting the issue, I'm down to the following and out of ideas:

My Controller:
Code:
<?php
class RSS extends Controller {
     function RSS()
     {
          parent::Controller();
     }

     function Index()
     {
          $this->load->view('activity_rss_view');
     }
}
?>

SO as you can see all i'm doing is loading a view, no helpers etc. My view is:
Code:
<?
echo '<?xml version="1.0" encoding="utf-8"?>' . "
";
?>

When I load that up I'm getting a single space in front of the <?xml.. is it just something obvious I'm missing or maybe something in my config?

Hope someone might have an input, scratching my head on this one.

JC
#2

[eluser]Daniel Eriksson[/eluser]
Maybe your editor is inserting the unicode BOM (Byte Order Mark)?

/Daniel
#3

[eluser]Vince Stross[/eluser]
just for kicks, try this

Code:
<?='<?xml version="1.0 encoding="utf-8"?>'?>

if there's still a space, then I would try removing the PHP code and doing a "Hello World" and see if there is still a space. If so then it might be your editor as Daniel E mentioned.
#4

[eluser]joncarl[/eluser]
It took me a bit but I finally found where the problem was, one of the custom libraries I was loading that extended sessions had an extra space in it at the eof that was translating over to the output. Sad
#5

[eluser]louis w[/eluser]
Ouch dude. Good catch.

In the future if you think there is a space somewhere put in a header('Location: test'); right before you output. It will throw a php error saying it can not redirect and should cite which document is causing the error (which file has the space).
#6

[eluser]mattpointblank[/eluser]
[quote author="joncarl" date="1206149787"]It took me a bit but I finally found where the problem was, one of the custom libraries I was loading that extended sessions had an extra space in it at the eof that was translating over to the output. Sad[/quote]

You, sir, are a hero. This was my problem too - it's the EckoTools Session Library - there's an extra space right at the end. Well spotted!
#7

[eluser]louis w[/eluser]
To prevent this from happening do not place a closing PHP tag "?>" at the end of your document.
#8

[eluser]Unknown[/eluser]
Cheers to joncarl for the catch!

I still end my files with the "?>" by habit but, if you do, check and make sure there is no space or newline after starting with your custom libraries and helpers and working up to the model/view/controllers. You'll find the bugger that will fix this issue.
#9

[eluser]Ninjabear[/eluser]
(This is an old topic.)

I had the same error and found I had a space before the opening php tag on on of my model files. To debug I just turned off all autoloads in config/autoload.php and then selectively put them back to see what caused the problem. Nice and simple.
#10

[eluser]sdjones[/eluser]
this is a very old topic now, however i had this problem and could not find any white space in any files, i don't use php end tags and there was no white space before my php start tags.

even var_dump()ing produced the same white space output (when you viewed source). Anyway i found that if i added:
Code:
ob_clean();

before my output it removed the white space - looks like there might be some whites space in the output buffer.
would recommend anyone else hitting this problem to check out http://php.net/manual/en/book.outcontrol.php

or just turn the output buffer off..




Theme © iAndrew 2016 - Forum software by © MyBB