Author Topic: [PHP] Problem with white spaces out of nowhere  (Read 683 times)  Share 

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
[PHP] Problem with white spaces out of nowhere
« on: 05 Sep 2011, 22:02 »
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]                            <div id='paper'>
                                   <?php
                                          include 'archiv/index.php';
                                   ?>[/code]

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

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.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Wyz

  • AGS Project Admins
  • anno 1986
    • I can help with AGS tutoring
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: [PHP] Problem with white spaces out of nowhere
« Reply #1 on: 06 Sep 2011, 00:36 »
Try and see if this makes a diffrence:
[code]                            <div id='paper'><?php
                                          include 'archiv/index.php';
                                   ?>[/code]
Life is like an adventure without the pixel hunts.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: [PHP] Problem with white spaces out of nowhere
« Reply #2 on: 06 Sep 2011, 02:56 »
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..!?
« Last Edit: 06 Sep 2011, 03:03 by Khris »
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

selmiak

  • Image Updaters
  • relax brain and neck
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with web design
    •  
Re: [PHP] Problem with white spaces out of nowhere
« Reply #3 on: 06 Sep 2011, 16:25 »
[code]                            <div id='paper'>
                                   <?php
                                          include 'archiv/index.php';
                                   ?>[/code]


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

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    •  
  • Darth Mandarb worked on a game that was nominated for an AGS Award!
Re: [PHP] Problem with white spaces out of nowhere
« Reply #4 on: 06 Sep 2011, 16:49 »
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: [PHP] Problem with white spaces out of nowhere
« Reply #5 on: 06 Sep 2011, 18:18 »
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.
« Last Edit: 06 Sep 2011, 18:21 by Khris »
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: [PHP] Problem with white spaces out of nowhere
« Reply #6 on: 06 Sep 2011, 19:17 »
Klaus Schlichter | weblog | newswall

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: [PHP] Problem with white spaces out of nowhere
« Reply #7 on: 07 Sep 2011, 02:16 »
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!
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"