Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 92
  • Last Modified:

php echo blank space

I include a php file into my page,
however a blank breakline is show up before my menu code begins

<?php include 'menu.php';?>

I start my menu include file like this

<?php echo'<div id="navMenu">..........

what should I do to get rid off the blank space?
0
Braveheartli
Asked:
Braveheartli
  • 6
  • 4
  • 3
  • +2
4 Solutions
 
Terry WoodsIT GuruCommented:
It's likely there's some blank space outside of the <?php ?> tags that is being picked up as literal code to output. If it's not in the file you're looking at, it might be in menu.php or another file being included/required.

eg:
 
<?php echo'<div id="navMenu">..........

Open in new window

0
 
Terry WoodsIT GuruCommented:
ie see how the first line is empty
0
 
BraveheartliMarketingAuthor Commented:
it seems like there is no white space... however i include this file in an empty php page, there is still an empty space above the page.
I think it is because of the file that i include
included file code is:
<div id="navMenu">
<ul><li> <a href="index.php">Anasayfa</a></li></ul>        
<ul><li> <a href="xxxx.php">Ürünler</a><ul>
<li><a href="xxx.php">xxx</a></li>
<li><a href="xxx.php"> xxxxx</a></li></ul>
</li></ul><ul><li> <a href="xxxx.php">xxxx ver</a>  </li></ul> 
<ul>
<li> <a href="mesaj.php">Mesaj Yaz</a> 
</li> 
</ul> 
<ul>
<li> <a href="duyurular.php"> Duyurular</a>  </li> 
</ul> 
<ul>
</li>
</ul> 
<br class="clearFloat">
</div>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Terry WoodsIT GuruCommented:
Do you see the space if you do a View Source of the page in your browser?
1
 
Julian HansenCommented:
Empty space in HTML is usually because of a padding or margin.
HTML by default ignores white space unless inside a <pre> tag - so if you are seeing a space above your menu I am guessing it is padding or a margin.

Can you post a screenshot?

Also, use F12 to get into the console. Click on the menu div in the HTML pane (left) and see what it shows in the browser (it will highlight the container) and in the css on the right.
1
 
Chris StanyonCommented:
It's possible that your 'blank line' is simply caused by margins or paddings - either explicitly from CSS or implicitly from your browsers defaults. It could be coming from the DIV or the UL.

You can solve it by setting the margins and paddings to 0 on your navigation elements. And if you haven't already, include some form of normalisation CSS to reset all browsers to a level playing field.
1
 
Ray PaseurCommented:
HTML "almost" ignores white space.  For normal display, most browsers will collapse contiguous white space (blank, tab, newline, etc) into a single blank character.  If you're not seeing that effect, it's likely that CSS is in play.  You can see the true HTML document with "view source."  And +1 for using the console, as well as other dev tools.  They are really helpful!

If you can post a link to the web page with the unwanted white space, we might be able to find the specific issue.
0
 
BraveheartliMarketingAuthor Commented:
now I realize that it works perfectly fine on Explorer browser however, on Chrome it has a white space..

I discovered on the Chrome dev tool that it shows margin 8px;
however, I don't have a code on my css file like this. Does Chrome do that?

body {
    display: block;
    margin: 8px;
}

Open in new window

0
 
BraveheartliMarketingAuthor Commented:
this is the where I include my php file:
Please see the picture attached
Capture.JPG
0
 
BraveheartliMarketingAuthor Commented:
when I include text ( string ) instead of navigation menu, it works.. no white spaces
0
 
Ray PaseurCommented:
...don't have a code on my css file like this. Does Chrome do that?
Yes.  Most browsers provide some kind of "boundary" whitespace around page elements.  You might try using a "CSS reset" like this.  These give you far more precise control of the viewport.
http://meyerweb.com/eric/tools/css/reset/
0
 
Chris StanyonCommented:
Yeah - as I said in my previous comment, each browser has it's own defaults, so you are always better off levelling the field.

Rather than using a reset (as Ray mentioned) I would suggest you noramlize your CSS. This has the added bonus of not removing all styling like a reset, but ensuring that everything is styled consistently across browsers.

It's as simple as adding a reference to a normalising stylesheet BEFORE adding your own CSS. Here's a good one to use that's hosted on a CDN:

https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css
1
 
Ray PaseurCommented:
Whether you "reset" or "normalize" the point is the same - get all the browsers started on the same footing, so your application-specific style sheets will have the same effect in all the browsers!
0
 
BraveheartliMarketingAuthor Commented:
Thank you all
0
 
BraveheartliMarketingAuthor Commented:
I found this answer,
this answer solve the problem. It was because of the php BOM problem.

https://www.sitepoint.com/community/t/php-include-menu-class-active-css/11412
0
 
Ray PaseurCommented:
PHP does not have a BOM problem, per se.  This article has some information on the BOM.  TL;DR Always remove the BOM from UTF-8 documents.  UTF-8 is self-describing and the BOM only causes trouble!
https://www.experts-exchange.com/articles/11880/Unicode-and-Character-Collisions.html
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now