en jp ru it gi" /> en jp ru it gi" /> en jp ru it gi"/>

php echo changing the spacing of elements

501 Views Asked by At

When I do this

<li class="language">
   <a href="felt.php?lang=en">en</a>
   <a href="felt.php?lang=jp">jp</a>
   <a href="felt.php?lang=ru">ru</a>
</li>

it gives me space between the a tags, with space

with space

but when I do

  echo '<li class="language">';
  echo '<a href="felt.php?lang=en">en</a>';
  echo '<a href="felt.php?lang=jp">jp</a>';
  echo '<a href="felt.php?lang=ru">ru</a>';
  echo '</li>';

It takes away the spaces. why is this? I have not applied any css...

2

There are 2 best solutions below

0
MaxiGui On

It is because you are writing it wrong, you should write it like:

echo '<li class="language">
    <a href="felt.php?lang=en">en</a>
    <a href="felt.php?lang=jp">jp</a>
    <a href="felt.php?lang=ru">ru</a>
    </li>';

In your case, the echo will consider it as inline so it will delete the space, if you want to keep your structure you can always add it like:

echo '<li class="language">';
echo '<a href="felt.php?lang=en">en</a>';
echo ' ';
echo '<a href="felt.php?lang=jp">jp</a>';
echo ' ';
echo '<a href="felt.php?lang=ru">ru</a>';
echo '</li>';
0
Alex On

In php echo doesn't add any space or new line in the end of output.
This code

  echo '<li class="language">';
  echo '<a href="felt.php?lang=en">en</a>';
  echo '<a href="felt.php?lang=jp">jp</a>';
  echo '<a href="felt.php?lang=ru">ru</a>';
  echo '</li>';

will be translated as if you write html in one line.

<li class="language"><a href="felt.php?lang=en">en</a><a href="felt.php?lang=jp">jp</a><a href="felt.php?lang=ru">ru</a></li>

And if you care how browsers treat whitespace Mozilla have a good article - How whitespace is handled by HTML, CSS, and in the DOM