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
35
Other forums
start new row of pictures
on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get
Multi image upload
I have a gallery to build and want to build a dynamic upload form to allow for $var number of fields
Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to
Upload, SSL and more php help
I recently just installed a ssl cert and do i use https for the whole site or just for the checkout.
Sending an SMS Message with ASP.NET
Often times it may be a requirement for your web application to send an SMS message. Such examples w
mysql VARCHAR acting like INT
Hi, All.
I have a table that contains a varchar(10) column named weird_field. In this column
Unable to customise toolbar in FCK
FTP Programs
Here is a list of commonly suggested FTP Programs to use:
FileZilla
SmartFTP
CuteFTP
Error in query: Resource id #4??
hey guys, having a minor (i think) problem here that i havent been able to figure out. long story sh
Alternate messaging
I have 4 strings in MySQL db1
$string1 : Hello
$string2 : Hi
$string3 : Great
$strin