I've looked at several solutions from various search engines, but I haven't found one that has worked just yet. I have a textarea that is displaying a php variable in it. Instead of linebreaks, it simple shows <br />'s, everywhere. I tried replacing them with /n's and various other things, but I haven't had any luck.

Is there an easy solution? This one little issue is holding me back tremendously.

Thank you in advance,

Resentful

Dani AI

Generated

Browsers render the contents of a textarea as plain text, so any HTML markup stored in the string will appear literally instead of producing line breaks. was on the right track pointing at using actual newline characters; the remaining problem is commonly that the source contains HTML break markup or that the markup has been HTML‑escaped before being sent into the textarea.

A simple, safe workflow:

  • If stored text contains HTML break markup, convert those substrings to newline characters on the server before placing the text into the textarea (use a basic string-replace routine such as str_replace).
  • Perform that conversion before you HTML-escape the output. Use an escaping helper like htmlspecialchars when outputting the final value so you avoid XSS while keeping real newlines intact.
  • If data in the database already contains escaped entities, decode them first with html_entity_decode, then replace the break markup.

Troubleshooting tips: if literal break markup still shows, check for double-encoding (stored escaped HTML), and confirm the text is being placed between the textarea tags rather than mishandled as an attribute. When you later display the same content as HTML (not inside a textarea), convert newline characters back to HTML breaks at render time (for example with nl2br). likely resolved it by converting the stored break markup to real newlines before escaping and output.

Recommended Answers

All 5 Replies

Try using '\n' instead of '/n'

Try using '\n' instead of '/n'

My bad. That's what I used. I just typed it wrong. When I did that, it did the line breaks, but the <br />'s stayed.

Oh, maybe include the code so we can see and try to help

I fixed it myself.

Thank you for the help.

No problem, just out of curiousity (and for my future reference) what did you have to do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.