Reputation: 15
I need to know how to echo a line break from my database in a textarea as html rather than text.
Upvotes: 0
Views: 2368
Reputation: 270
Hye this works for me!!! I think this may help you..
my table has two columns 'a' and 'c';
values are 'aa' and <input type="text">
My code:
<?php
$host='localhost' ;
$mysql_db="db2" ;
$mysql_u="root" ;
$mysql_p="" ;
$con=mysqli_connect( "$host", "$mysql_u", "$mysql_p","$mysql_db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
$c="select c from site where a='aa'";
$res=mysqli_query($con,$c);
while ($row = mysqli_fetch_assoc($res)) {
$a=$row['c'];
echo "<textarea>$a</textarea>";
}
}
?>
This outputs a text box in browser... :)
Like this you can store '<br>
' in table for col 'c' it outputs a new line...
for ur question this is the exact answer... use the code edited above... but change in db
for ex here, in column 'c' change entry as stmt1 stmt2 stmt3
you will get these three stmts in three lines(like
in html)
- Line Feed and
Carriage Return are HTML entities
Upvotes: 2
Reputation: 3557
Simply use htmlentities($yourString). This will convert
into new line. For reference:
http://www.php.net//manual/en/function.htmlentities.php
Upvotes: 0
Reputation: 1070
I'd write a function that converts linebreaks to new lines and run that. That's presuming I understood you correctly and you want to return
into linebreaks.
function br2nl($content)
{
$content = str_ireplace("<br /> ", "\n", $content);
return $content;
}
Simply use this function on whatever content you wish to revert back.
Upvotes: 0