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

Amend code to allow multiple attachments
Hi

I have a php page that allows the user to browse to a file (image) then sumbit, the confi

Thread in PHP
Thread in PHP
Some basic use and basic code for thread in php
This is my question?

PHP & Images [Resize, Crop, Save]
Hey! Well I have a little dilema, hoping I could find some guidance.

I have a CMS and on the

How to get variable value on next page
Hello friends
i am working on payentry page ..there i have this code.........

Need help in log in and log out?
hi there all of u. i have recently created a site for someone. i have placed log in and log out and

php mail form text wont appear / javascript included
Guys/gals...

I am running into a problem whereby I have a great piece of javascript code that

cURL and Sessions
Ohai.

So, I'm trying to cURL a bunch of things off of a page, and put them into a session. I'

Error In Syntax
I got this error:

Code: Parse error: syntax error, unexpected '>' in /home/bucket/publ

Upload simple problem
Really confused!! I run once and it worked, but when i tried today...it didn't work

Which par

Select question
Hi,

First I would like to say that php is pretty new for me..
so please don't shoot me if

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