Solved

php echo blank space

Posted on 2016-10-25
17
29 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
  • 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
 
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 51

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 42

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 108

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 108

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 42

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 108

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
echo button 13 48
How to remove decimals from calculation amount 8 25
Web Reply Form - PHP with Upload 4 22
PHP JSON Clean up 5 10
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now