In most cases, as for one interactive website, when we output multiple lines of contents to web client browser, in my opinion, <BR /> is much more preferable than other two: \n or PHP_EOL.
Else, we need to use "<pre></pre>" to wrap the output content or use nl2br() to insert <BR /> before \n so as the multiple line mark can take effect in HTML. Like following example.
$fruits = array('a'=>'apple', 'b'=>'banana', 'c'=>'cranberry');
// Multiple lines by \n
foreach( $fruits as $key => $value ){
echo "$key => $value \n" ;
}
// Multiple lines by PHP_EOL
reset( $fruits );
while ( list($key, $value) = each( $fruits ) ){
echo ("$key => $value" . PHP_EOL);
}
// Multiple lines by <BR />
reset( $fruits );
while ( list($key, $value) = each( $fruits ) ){
echo ("$key => $value <BR />");
}
Some people believe PHP_EOL is useful when writing data to a file, example a log file. It will create line breaks no matter whatever your platform.
Then, my question is when we use \n? What's the difference between \n and PHP_EOL, and <BR />? Could any body have a big list of each of their pros and cons?