2

I'm having troubles with multiple html pages include. I had main index.html but it started to be a bit too complex so I decided to split it in multiple html files and each one of them inport into single index.php using php.

index.php file

<?php
include('head.html');
include('header.html');
include('slideshow.html');
include('pictureGalery.html');
include('footer.html');
include('closer.html');
?>

using Google Chrome Developer Tool I found, that php includes included also some white spaces (you can see them in picture in between of divs header, content, container etc... With a bit of googling I found some arciles about this problem, like:

I also tried to import reset.css file (http://meyerweb.com/eric/tools/css/reset/) but it didnt work either. The only way that seems to work for me is one that posted cebasso (https://stackoverflow.com/a/14362246/1784053). But I find this way a bit too agresive and unefective.

Any other ideas how to fix this problem?

enter image description here

Community
  • 1
  • 1
Kajiyama
  • 3,163
  • 7
  • 23
  • 37
  • 1
    `but these whitespaces are not visible in notepad.` -- Notepad isn't the only text editor. Try a different one, perhaps? Try Notepad++. – Amal Murali Sep 12 '13 at 20:43
  • Also make sure your included files don't have trailing empty lines, php include will add them to the original doc – jayadev Sep 12 '13 at 20:50
  • +1 for Notepad++ my favorite text editor. – Lumberjack Sep 12 '13 at 20:50
  • @AmalMurali Notepad++, VisualStudio 2010, Dreamweaver, Eclipse.. all the same. I dont see these 3 BOM characters – Kajiyama Sep 12 '13 at 21:00
  • @jayadev There are no empty lines in before or after the code – Kajiyama Sep 12 '13 at 21:01
  • You can try **print_r(array_map('dechex', array_map('ord', str_split(file_get_contents("xxxxxxxx.html")))));** to see if there are any problems on the file itself first :) replace the xxxxxx.html first – Michael Mitch Sep 12 '13 at 21:20
  • Removing the closing php tags `?>` from you php files could help. – Joren Sep 12 '13 at 21:22
  • @michaelMitch using your posted code I found, that first 3 characters are BOM characters> ï»û – Kajiyama Sep 12 '13 at 21:34
  • Hi, kajiyama, then they are there, you can save your file without BOM using notepad++, or just BRUTALLY remove them as you see fit using any methods. – Michael Mitch Sep 12 '13 at 21:44
  • If you want to remove it by PHP, use the code in the answer i posted here, pasting it in comment is clumpsy. :( – Michael Mitch Sep 12 '13 at 21:57

3 Answers3

0

Then, ends up this is caused by unexpected BOM on the file that are included: For future reference, I just post the code used to check by PHP plainly.

print_r(array_map('dechex', array_map('ord', str_split(file_get_contents("xxxxxxxxxxxxx.html"))))); 

I would definitely prefer using Notepad++ or other software to save a non-BOM version, but if still prefer using PHP to remove them, just use: This removes first 3 characters in the file PERMANENTLY every time you execute it, so run once only.

$filename="xxxxxxx.html";
$filec = file_get_contents($filename);
file_put_contents($filename,substr($filec, 3, strlen($filec)));

Hopes it helps :D Good luck!

Michael Mitch
  • 559
  • 3
  • 12
  • As I have said in my question, at the moment I am using technique like you posted and works for me. I was just trying to find something clearer. Anyway thanks for help :) this will have to suffice. – Kajiyama Sep 12 '13 at 21:55
  • No, if you look closer, it is replacing the file by overwrite with **a no BOM version**. Please see the file_put_contents – Michael Mitch Sep 12 '13 at 21:59
0

I have the same problem before a moment. but when I see BOM characters, I think of a solution. Am not sure, but these characters for utf-8 encoding. I save my included file as ansi and the problems solved. also it's works fine with encode in utf-8 without BOM in Notepad++
Thanx

Regards

Saif Hamed
  • 1,064
  • 11
  • 17
-1

I'd look closely at your included files. Ensure that there is no white space at the top or bottom of every one of those documents. White space is not ignored by php and will definitely be included.

rfoo
  • 1,100
  • 1
  • 12
  • 27