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

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

Web Application Recipe
Hi Guys!

I am working with the Web Application recipes. I am currently working on the sen

Recognising Revenue daily
Hello.
Has anyone come across daily recognition of deferred income?
We want to implement R

problem when runing a funciton
I am trying to connect to database using a funciton in a functions.php

<?php
funct

RSS feed - FeedList for WordPress
Hi,

I'm trying to alter the FeedList plugin for WordPress so that I can click on the title of

Need help with PHP/MySQL drop down menu
I need help on how I can implement a drop down menu which queries mysql database and output the avai

CHECH A STRING FOR ' " ' (DOUBLE QUOTES)
I am checking for delimiter (.!?) and if there is a " after a sentence then it should neglect a

PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is

Collecting AOL Search Terms
I am attempting to collect AOL search terms. I know the code is correct (it works for google, bing,

Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
My application wants to send/recv data to 2 different UDP ports on a remote computer, us

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