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

Session
I am having a little trouble with a session. Not sure if it is my browser or what. I know I do not

Email Script does not reach destination
Hey Guys look at this code snippet :
Code:
//read a line from the file

$myFile = "

Help with writing "$" with fopen
I just can't get my syntax correct. Could someone help me please? I am trying to write a connect fil

Filtering Tables
Hello Thanks for any help any one can give Im very new to PHP..

I need to pull data for clien

MVC - Code review
I'm in the process of trying to wrap my head around MVC, and as part of that, I'm attempting to impl

how to load a Sys file with system load and call images?
normally you need register the module as a service with CreateService, and start the service

CURL XML Request [From C to PHP]
Hi,

I need some help converting this into something that will work with PHP.

Code: #

GIS appliction help
I found some tutorials in the internet to develop a map application I don't want to use google maps

How to show more than 1 users with this code...
Hello,
i have a table that shows users only if I, as Administrator, want to be shown. But its sho

PHP onsubmit in the form not going to the fuction.
I have a form through ‘onsubmit’ calling a function validation(). But not going to the

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