1

I am storing user inputs in my DB unencoded, this includes line breaks in the data. There are no \n or <br>'s in the inputs when then displaying the data again so the line breaks are lost.

I have tried wrapping the output in htmlspecialchars but it has not made a difference.

How can I accurately display this content?

2 Answers 2

8

You can use nl2br():

$data = nl2br($data);

This adds HTML line breaks <br> before PHP line breaks \n.

Sign up to request clarification or add additional context in comments.

Comments

0

You Can also Used this. PHP generates HTML. You may want:

echo "foo";
echo "<br />\n";
echo "bar";

I think, It is used full to you.

Thank You..

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.