-1

Input text :

Test one two three fourfive

Text is splitted by preg_split with additional processing and now result array is:

Test one
<span>two</span>
three
<span>four</span>
five

When I echo this array in loop I get this:

Test one two three four five

Four and five should be displayed together, without space.

In HTML source it looks like so:

Test one
<span>two</span>
three
<span>four</span>
five

Extra space is added after four.

When I directly write this in HTML

Test one <span>two</span> three <span>four</span>five

text is echoed correctly. It seems that new line in HTML add extra space. Does someone know what happens here?

casperOne
  • 70,959
  • 17
  • 175
  • 239
savgoran
  • 55
  • 6

3 Answers3

3

According to W3C, newlines are whitespace characters and should be rendered as a space by browsers.

If you want to get rid of the space, use <pre> and format your text as needed, or modify your markup so you can left-float "five."

George Cummins
  • 26,731
  • 6
  • 65
  • 89
2

A newline is a space. Remove that and your space disappears.

Niet the Dark Absol
  • 301,028
  • 70
  • 427
  • 540
0

Remove \n from your echo and it should be fine.

Just like OP suggest newline is whitespace too.

Jacek Pietal
  • 1,918
  • 1
  • 17
  • 27