1

I just started learning how to make a website. I'm making a comment box which is used to enter blog entries. Let's say I types in an entry with 3 lines, and it will show up the same format in mySQL table. But when i try to output it, it becomes one line.

//Here's what i did to output the data.
$entry = $row['entry'];
echo "<p>". $entry ."</p>";

//INPUT
Hello,
TEST LINE2
TEST LINE3

//OUTPUT
Hello, TEST LINE2 TEST LINE3
1
  • 1
    If you start lerning try to use mysqli in youre web-sites Commented May 19, 2012 at 18:19

3 Answers 3

5

You could use http://php.net/manual/en/function.nl2br.php

"Inserts HTML line breaks before all newlines in a string"

$entry = $row['entry'];
echo "<p>". nl2br($entry) ."</p>";
Sign up to request clarification or add additional context in comments.

Comments

2

Wrap it in a pre tag, this will prevent white spaces from breaking.

$entry = $row['entry'];
echo "<p><pre>". $entry ."</pre></p>";

2 Comments

@ylhtravis what css are you using?
You can style the <pre> tag with CSS as well.
0
$entry = $row['entry'];
echo $entry ."<br />";

Or

$entry = $row['entry'];
echo $entry ."<br>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.