Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:03:55+00:00 2026-05-26T10:03:55+00:00

I’m echoing a series of HTML elements using PHP. I’m using \n to cause

  • 0

I’m echoing a series of HTML elements using PHP. I’m using \n to cause code line breaks to make the source code more organized and legible.

For some reason, the use of \n in a specific location is causing a mysterious gap between the HTML elements. In firebug, this gap is not showing up as a margin, or padding, but rather just a gap.

Here is the PHP in question:

Note: As you can see, I have removed all of the PHP inside the tags as I’m pretty sure it is not relevant to this problem.

echo '<ul ... >'."\n";
while($row = mysql_fetch_assoc($result_pag_data)) {

    echo '<li><a ... >'."\n".
                '<img ... >'."\n".
          '</a></li>'."\n"; <---- THIS IS THE \n THAT SEEMS TO BE CAUSING THE GAP
}
echo '</ul>'."\n";  

Have you ever seen anything like this before, a presentation gap associated with PHP line breaks?
If so, what is the reason for it?

Is it really that important that I use \n in my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:03:56+00:00Added an answer on May 26, 2026 at 10:03 am

    That’s normal. A \n line break has no meaning in HTML, so it’s interpreted as a space character. If you don’t want that gap, then eliminate the \n, or rewrite the html so it’s not relevant:

    <li><a ...><img ...></a></li>
    

    As a general rule, tags which can contain text should never have their closing tags on a line by themselves, for this very reason.


    Following up on your ‘where to put \n’ question. This comes down to personal preference, but I tend to format my html like this:

    <table>
    <tr>
       <td><a href="some big long ugly url">
               <img ....></a></td>
    </tr>
    

    Since <tr> can’t contain any text on its own (in valid html), it’s ok to put on its own line. But the </a> and </td> are both tags that CAN contain text, so I put them right up against the end of the ‘text’ (the img tag in this case), so that the Phantom Linebreak Menance (coming soon to a starwars ripoff near you) can’t strike.

    Note, of course, that my example does have a line break and indentation between the opening <a> and the <img> tag, so that’s another place where a “must be right next to each” other layout would cause a gap. If you need a series of things lined up smack dab against each other, than you basically can’t use line breaks anywhere in that section of the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.