Preserving user-entered linebreaks


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I'm building a web 2.0 thingy from scratch and I wanna display text which users input. It's all good so far, except that all the linebreaks are destroyed, so no matter how carefully they insert whitespace, their input gets displayed as one big block of text.

The data is submitted (method="post") through a textarea. The mysql_real_escape version is stored in mysql. Then it's read from the database (no unescaping necessary) and passed through htmlentities before being printed into the body of the webpage.

I tried replacing htmlentities with the following function:

Line number On/Off | Expand/Contractfunction brentities($x){ $x = str_replace("[LINEBREAK]","nr",$x); $x = str_replace("[LINEBREAK]","rn",$x); $x = str_replace("[LINEBREAK]","n",$x); $x = htmlentities($x); $x = str_replace("<pre>n</pre>","[LINEBREAK]",$x); return $x;}

But this doesn't seem to work. I also tried setting "white-space: pre;" in the CSS for the appropriate div, but that caused the text to bleed outside the div (and even outside the screen), so no go

What's the best way to settle this issue?

Thanks

No comments posted yet

Your Answer:

Login to answer
53 Like 35 Dislike
Previous forums Next forums
Other forums

xApp Analytics in BI 7.0
Dear all,

I am trying to implement xApp Analytics in BI 7.0. After I installed the analyt

Unifying logins of two different scripts
I have two different game scripts which I want to embed on my own site. The problem is I don't want

When file included, REMOTE_ADDR is server's?
I have an index file that handles my site, basically index.php?page=ip will activate "require('

help with calculations on a flat text file
hello,
I have this code below that is attached to a flat file like this:
Email:LastName:FirstN

Undefined offset
The following script checks to see if the user answer matches the correct answer.

Form Fiel

natcasesort works on one server but not on another
Hi

I have a problem that I was hoping that someone can help me with.

I'm trying to use

start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get

Extra fields in main body and php required.
I'm new to PHP so please be gentle. I have a little php script below that works well.
The &quo

How to show a complete textarea ??
I enter Client Case Notes notes in a textarea field on a PHP form. The field is 5 rows deep and 70 c

sendmail code suddenly not working
Hi Guys, I maintain 3 sites (including my own) I use the following code from a french webmaster that

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash