/    Sign up×
Community /Pin to ProfileBookmark

Displaying back user submitted multiline text

Hi, I could sure use help on this one.

I have a form with 2 multiline input fields. When I enter line breaks for my next paragraphs these “<br/>” get entered into my database.

Problem is when I return the data from the database, I can’t get the (<br/>) line breaks and other html to do their job and display a space in the text or other stuff it should. The html instead gets displayed along with text.
————————————————

If I enter this info:

I’m a dumb boy.

I’m sure that [2+3=4].
————————————————

I get this for display:

I’m a dumb boy.<br /><br />I’m sure that [2+3=4].

How can I make those line breaks not display, and behave like they should to perform a line break when rendering output? I want it to display exactly as I typed it in. Any clues. Code example would be helpful, if you can write it I can grasp it.

Thanks (I could not find direct references regarding this @ php.net)

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@benifactorMar 03.2007 — it would help us to help you if you showed us your code...but...

try

stripslashes($string);

so

[code=php]$newdata = stripslashes($originaldata);[/code]

hope it helps. let us know.
Copy linkTweet thisAlerts:
@WebjedikungfuauthorMar 03.2007 — That was too easy. Thanks benifactor
Copy linkTweet thisAlerts:
@benifactorMar 03.2007 — no problem. any time.
Copy linkTweet thisAlerts:
@WebjedikungfuauthorMar 03.2007 — K, how bout later??
Copy linkTweet thisAlerts:
@knowjMar 03.2007 — if i understand you correctly your putting the <br/> tags into the database?

there isn't really much need to do this as nl2br($content) would turn all the new lines into <br/> tags when its viewed.

I wish there was a nl2p command as i hate using <br/> i always feel like im doing a bodge job.

altho saying that formatting by new line has turned out to be a problem for me with validation when i add lists etc... to my blogs.

im currently having to rewrite it.
Copy linkTweet thisAlerts:
@WebjedikungfuauthorMar 04.2007 — I'm trying to filter(secure) the data in the script that uploads the user

multiline text info into my DB.

When I clean(filter) the text in this way my output goes whacko(it strips important html structure I need to retain):
[code=php]
$the_goods = nl2br(htmlspecialchars($_POST['the_goods']));
$the_goods = mysql_escape_string($the_goods);
[/code]


So with the way I'm cleaning it, even if I use "stripslashes($string);" to output the data back to user it has lost it's structure.

Does anyone know a good "filter then return" mechanism that will retain the user's html structure(multiline text)? I need to filter it, and also retain exact structure.
Copy linkTweet thisAlerts:
@WebjedikungfuauthorMar 04.2007 — Sorry I posted up, but was wrong so I editted it, my bad. I'll get a working example up if no one else does
Copy linkTweet thisAlerts:
@WebjedikungfuauthorMar 04.2007 — OK, I supplied an example of fixing the filtered user data. May need more.

"strip_tags" along with "stripslashes" http://www.audiopeeps.com/testforWD2.php

Code for file in that ^ link ^
[code=php]
<?php
// Filter the data
$the_goods = nl2br(htmlspecialchars($_POST['the_goods']));
// Below line is for use in DB filtering, commented out for test
//$the_goods = mysql_real_escape_string($the_goods);
?>
<html>
<body>
<p>1. Type one line.
2. Press enter twice.
3. Type another line.
4. Then hit send.
</p>
<form action="testforWD2.php" method="post" enctype="multipart/form-data" target="_self">
<textarea rows="9" cols="50" name="the_goods" ></textarea>
<input name="submit" type="submit" value="SEND" />
</form><br>
Normal<br>
<?
$var1 = ($the_goods);
echo '<textarea rows="9" cols="50" name="d3f_bio" >' . $var1 . '</textarea><br>';
?>
With fixes<br>
<?
$var2 = strip_tags($the_goods);
$var3 = stripslashes($var2);
echo '<textarea rows="9" cols="50" name="d3f_bio" >' . $var3 . '</textarea><br>';
?>
</body>
</html>
[/code]


Thanks guys
×

Success!

Help @Webjedikungfu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...