1

Possible Duplicate:
Why does PHP echo'd text lose it's formatting?

I got strange problem. Let's say I got code like this:

<?php

class Bar
{
    private $foo;
    function __construct ($foo)
    {
        $this->foo = $foo;
    }

    public function testFoo($obj)
    {
        echo $obj->foo . PHP_EOL;
    }
}

$obj = new Bar("obj");
$obj2 = new Bar("obj2");
$obj->testFoo($obj);
$obj->testFoo($obj2);

?>

And well instead of getting expected result which is:

obj
obj2

This is what I get:

obj obj2

It's just like PHP_EOL represents blank space. I also tried to use "\n" but this one works same. I'm using latest XAMPP.

Community
  • 1
  • 1

1 Answers1

2

If you are viewing this in your browser, it's because browsers interpret newlines in HTML as regular space characters.

In HTML you need to use <br> for forcing a line break.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Or you can send your output as plain text using `header('Content: text/plain');` - depends on what you're doing. – BoltClock Nov 22 '11 at 16:42