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:
or PHP_EOL
.
Else, we need to use "<pre></pre>
" to wrap the output content or use nl2br()
to insert <BR />
before
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
foreach( $fruits as $key => $value ){
echo "$key => $value
" ;
}
// 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
? What's the difference between
and PHP_EOL
, and <BR />
? Could any body have a big list of each of their pros and cons?
question from:
https://stackoverflow.com/questions/21373478/n-vs-php-eol-vs-br 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…