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

Last Weeks sDate and eDate.
sDate - Start Date
eDate - End Date

I need to pull two dates for "Last Week" whi

Dynamically allocating the number of rows in a table based on a variable value
Hi,
I have situation here which i cannot resolve, I have a variable temp which stores the num

Create or replace package is ending ORA-21700
Database 9.2.0., patch 8 (9.2.0.8.0).
I trying run
create or replace package ....etc.

Escaped characters
I have a script that allows you to post news to the home page of my site. Along with the news is the

ctype() validation - allowing illegal characters
Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain c

Php WordPress help
I am writing the following code for making a plugin

<?php
header("Content-Type

Securing a user input - need some confirmation
Hello All,

I am in the process of recoding a large proportion of an e-commerce site, one of t

Perplexing problem showing a .jpg
Please disregard..........I figured it out

frames get header location..
i have two frames, one top, one bottom. how do i do a form on the bottom frame that gives me the ur

Which PHP-Editor do you think is the best?
Hi everyone,
Myself Brian Anderson. For the last 2 years i have been working a

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