line break help in PHP
<?php
$sql="SELECT * FROM parentid WHERE id = '$doi'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$abc_output .= $row['title'] . "\n" ;
$abc_output .= $row['reportno'] . "\n" ;
}
}
echo $abc_output;
?>
Above is the following code i am using.. i want the output to be
title
reportno
but the output i am getting is
title reportno
can any one suggest me what i am doing wrong in line brea开发者_StackOverflow社区k ??
You need to add a <br />
tag to your output
$abc_output .= $row['title'] . "<br />" ;
$abc_output .= $row['reportno'] . "<br />" ;
Are by chance looking output in browser? Browsers want HTML linebreaks unless the data is in text format (php by default is not), so it won’t get rowed correctly.
If you want in your source code a line break You must use CRLF (Windows Systems):
"\r\n"
But if you want to display a line break you must use <br>
tag.
The line breaks are like if your press enter when you are writing code, thing that HTML cant interpret and display like a line break. So if you want to display line breaks you need to use <br>
There are three ways:
- Use
<br/>
tags, as some are suggesting. - Use the
<pre>
tag around your linefeed-formatted content. - Use CSS property
white-space
on a parent/containing element.
Note they all work in a PRE
tag, or in a tag with a white-space: pre
property.
http://www.quirksmode.org/css/whitespace.html
Here is a demo of all three.
div {
white-space: pre;
}
<pre id="pre"></pre>
<div id="div"></div>
$('pre').html("this\nis\na\nline break.\n\nthis<br/>uses<br/>HTML<br/>line breaks.\n\n");
$('div').html("this\nDIV\nuses\na\nwhite-space.\n\nthis<br/>DIV<br/>uses<br/>HTML<br/>line breaks<br/>in<br/>a<br/>white-space<br/>element.");
This outputs:
this
is
a
line break.
this
uses
HTML
line breaks.
this
DIV
uses
a
white-space.
this
DIV
uses
HTML
line breaks
in
a
white-space
element.
http://jsfiddle.net/fzz3s/1/
You can use <pre>
tag when sending new line character
精彩评论