Solved

php echo blank space

Posted on 2016-10-25
17
46 Views
Last Modified: 2016-11-03
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
Comment
Question by:Braveheartli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
17 Comments
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 125 total points
ID: 41858144
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 41858145
ie see how the first line is empty
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 41858155
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!

 
LVL 35

Expert Comment

by:Terry Woods
ID: 41858157
Do you see the space if you do a View Source of the page in your browser?
1
 
LVL 57

Assisted Solution

by:Julian Hansen
Julian Hansen earned 125 total points
ID: 41858271
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
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 125 total points
ID: 41858272
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
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 125 total points
ID: 41858344
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 41858442
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
 
LVL 1

Author Comment

by:Braveheartli
ID: 41858451
this is the where I include my php file:
Please see the picture attached
Capture.JPG
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 41858463
when I include text ( string ) instead of navigation menu, it works.. no white spaces
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41858503
...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
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 41858514
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41858533
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
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 41859367
Thank you all
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 41871652
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41872147
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question