[PHP] Problem with white spaces out of nowhere

Started by Khris, Mon 05/09/2011 22:02:42

Previous topic - Next topic

Khris

Alright, I'm adding some stuff to a website and all of a sudden I get like 30 or 40 spaces in between my divs that screw up the layout:

Here's the piece of code for the main page:

Code: ags
                            <div id='paper'>
                                   <?php
                                          include 'archiv/index.php';
                                   ?>


The first lines of the included file:
Code: ags
<div style='position: relative;'>
       <div style='position: absolute; left: -110px; width: 100px; padding: 0; margin: 0;'>
              <div class='archive' style='text-align: center;'>


When I look at the source in chrome, there's lots of white space after <div id='paper'>.
Naturally, I squished everything together as far as possible (although I had never to do that in the past) and what used to be
"                                                                     " ends up being "".
Still, it's treated as a line of text and Chrome even shows it as text element.

I can't get rid of it and the baffling thing is that this is by far not the only include and everywhere else, the source code lines up perfectly in Chrome's source code view.

Has anybody encountered something similar?
Btw, all my source files are encoded in UTF-8, so I'm pretty sure that conflicting encoding can be excluded as the source of the problem.

Wyz

Try and see if this makes a diffrence:
Code: ags
                            <div id='paper'><?php
                                          include 'archiv/index.php';
                                   ?>
Life is like an adventure without the pixel hunts.

Khris

#2
That was the first thing I tried :)

The problem is, even if that were the cause of the problem, why isn't it happening further down in the file where there are empty lines and lots of tabs between the tags?
It almost seems like a bug at this point, it does look the same in firefox and chrome though.

I've looked at the source in firefox again and I've noticed that some tabs end up as spaces and other don't (they remain tabs). What the hell.

I'm using Notepad++ btw.

Edit: when I inspect the text, it says the contents is " followed by return arrow or linebreak, I guess.
If I put echo "t"; above the include line, I get "t" in the source. Where are those goddamn quotes coming from..!?

selmiak

Code: ags
                            <div id='paper'>
                                   <?php
                                          include 'archiv/index.php';
                                   ?>



ever tried to delete this whole block an write it again, maybe some obscure special characters got in there...

Darth Mandarb

I'm not a php guy (coldfusion for-eva!!) but my first guess would be that there's something in the include file that's causing it and not this block of code itself.

Line breaks in html can cause a bit of space, but not in the volume you're talking about!

Is it possible for us to see the index file's code?

Or...

Are you using any CSS for that div that might be influencing it?  Line-height, white-space, absolute positioning etc?  Any "blocking" calls that might throw off the layout?

I love these little mark-up mysteries!!  They always seem like you've found an instance of a browser's bug but in the end it's a missing comma or something :)

Khris

#5
selmiak: There's nothing in there at all unfortunately.

Darth:
I'm positioning a clickable image relative to the centered main page, offset to the left.
The div containing the image is positioned in relation to an empty div at the top of the main page, but this latter one isn't at the top, it gets moved down by the whitespace.

I've uploaded the files here: http://db.tt/ALWyuuB
Here's a live version: http://home.pages.at/choala/whitespace/

If you look at that using Chrome, right-click the little picture and select "Inspect element", you'll immediately notice the spaces.

The thing is, I tried to move around the divs encompassing the image; they used to be outside the included file. It seems like the whitespace is always inserted right before/at "<?php".

But, like I said, this doesn't happen anywhere else on the page.

Edit:
As a final test, I removed the php part and manually inserted the code supposed to be included; this of course fixes the problem, regardless of empty lines and tabs in between. Damn.

Klaus

Hallo Khris,

ich hab mir grade mal deine Dateien angeschaut und "archiv/index.php" verursacht das Problem, obwohl die Ursache nicht wirklich sichtbar ist: Ich hab die Datei (also nur die genannte "archiv/index.php") einfach ohne Ã,,nderung nochmal gespeichert (mit PSPad) und schon waren die Leerzeichen verschwunden. Die Dateigröße ist dabei auch um 3 Byte geschrumpft. Also irgendwas hängt da wohl drin...

Vielleicht einfach mal in einem anderen Editor (Windows Editor o.ä.) öffen und nochmal speichern oder mit Notepad++ in einem anderen Format zwischenspeichern und diese Datei dann nochmal mit der üblichen Codierung speichern... Etwas in der Art sollte klappen :-) Notfalls kann ich dir die Datei auch schicken ;-)

Viele Grüße und gutes Gelingen, Klaus

Khris

Danke, das scheints wirklich gewesen zu sein!

I converted the format to "UTF-8 without BOM", whatever that means, and Notepad++ crashed while or rather after saving; the thing is that it did the trick although I had to Ctrl-Alt-Del Notepad++ after that...

Thanks!

SMF spam blocked by CleanTalk