JeepFreak JeepFreak - 1 year ago 82
HTML Question

Text area to modify HTML - rendering line breaks

I'm loading a portion of an HTML page into a text area so that I can make small changes. All the HTML tags are shown along with the text, which is what I need to happen; I don't want a WYSIWYG editor or anything fancy.

The one thing I want is for line breaks to be shown in the text area in addition to the

tags otherwise it's a giant wall of text and it's really hard to proof read. I don't want the line breaks to be doubled after I save the modifications though as the next step will be to convert everything in the text area to a PDF file.

ETA: nl2br() doesn't work because there are no line breaks to begin with. The content is assembled from paragraphs in a MySQL database using a loop. The tags are inserted during the loop too.

What's the best way to do this? I'm using PHP.

Oh, PS - I'm aware of the security concerns of not stripping the tags. This page is for the admin (me) only and will be password protected.

Answer Source

Maybe you can filter those first, before showing to textarea? Something like this, maybe (add newline after the closing tag):

$rawhtml = str_replace(array("</p>", "</h1>"), "\n", $rawhtml);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download