Welcome Guest, Not a member yet? Register   Sign In
CI Appending a Space before initial output
#1

[eluser]quexal[/eluser]
Hello,
For some reason CI (Using version 1.7.0) seems to be adding an additional space before its' initial output. This is screwing up the validation of my XML feed.

UPDATE: <initial post removed>
See the post below... it seems that the CI core is doing this. Anyone have any clues?
#2

[eluser]quexal[/eluser]
See post below...
#3

[eluser]quexal[/eluser]
Still can't make it work.

I've just updated the App to CI 1.7.2

- No Effect.

I tried writing a test-script to see if it also created this problem:

Controller: test.php
Code:
&lt;?php
class Test extends Controller {

function Test()
    {
        parent::Controller();
    }
    
    
    function index()
    {
        $data['pagename'] = "Test Page";
        $this->load->view('test', $data);
    }
    
}
?&gt;

View: test.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?= $pagename; ?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;

... and in the output I still have a space present before the <!DOCTYPE declaration (not showing up in code view, but it is showing up in the output of http://ntbg.org/breadfruit/resources/test/.

Output
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Test Page&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;

I thought.. hmmn.. perhaps it's my server configuration... so I created a test.html file... no space... a test.php file (not processed thru CI and it has no space either.

So, it seems like CI is adding a space to the start of every script... anyone have any ideas what could cause this?

Has anyone experienced similar problems?
#4

[eluser]quexal[/eluser]
Ok... this is tooo strange.

I decided... ok.. lets download a fresh copy of CI 1.7.2, upload it, and see if it happens with the "Welcome" controller/view.

I did so, and there was no space added!

So, I said... lets try the "test" Controller (shown in the post above). And lo-and-behold, there was a space added just like before!

So, I thought... perhaps it's because the $data variable is being passed to the view... so I changed the welcome controller to pass a variable called pagename (just like the test controller). And still.. no space in the welcome controller/view, and a space in the "test" controller/view.

I'm befuddled. Any help?
#5

[eluser]quexal[/eluser]
After 3 hours of chasing down a space character, I finally found the problem.

In the "Welcome" controller, there was no closing PHP tag - ?&gt;

In all of my controllers, I always included the closing PHP tag (by habit).

As soon as I removed the closing PHP tag from my controller, the mysterious space at the beginning of the output disappeared!

Is it normal coding practice in CI to leave out the closing PHP tag ( ?&gt; ) from controllers? Is this documented anywhere?
#6

[eluser]cahva[/eluser]
Yes it is documented and even preferred not to use closing tag. This applies to all PHP scripts, not just CI based.
#7

[eluser]jedd[/eluser]
Hi quexal,

Three observations.

Append means to add to. The word you're looking for here is insert or perhaps prefix. Note that it is not prepend - an archaism that means something entirely different.

[quote author="quexal" date="1259027343"]
... seems to be adding an additional space before its' initial output.
[/quote]

While I'm giving out language tuition freebies - its never has an apostrophe after it like this. Possessive its has no apostrophe at all, in fact. The easy way to remember how to work with "its" is to consider whether the sentence makes sense if you convert "its" to "it is". If (and only if) it does, then you need an apostrophe (viz "it's").

Third, and very much most importantly, this error pops up in the forums every few minutes, but even more tellingly it's bold as brass as the sole entry under the Errors heading in the [url="/wiki/FAQ"]FAQ[/url].


Just for future reference ...
#8

[eluser]quexal[/eluser]
Haha.. thanks for the language lessons. As you can see I can't even grasp my native tongue much less a simple programming language.

Very strange that I couldn't find the solution by searching the forums, the CI website, and Google. I'll search harder next time.




Theme © iAndrew 2016 - Forum software by © MyBB