Jump to content

Text Formatting while displaying


timmah1

Recommended Posts

I'm having a heck of time figuring out the correct way to put text into the database without \\\\ being inserted.

 

 

And when I display it, it shows the \\\\\

 

Here is my insert

$description = mysql_real_escape_string($_POST['description']);

 

And here is my display

<?php echo nl2br($description); ?>

 

How can I display the text properly?

 

Thanks in advance

Link to comment
Share on other sites

Can someone take a look and tell me what I'm doing wrong?

 

I insert the text into the database like so

$description = mysql_real_escape_string($_POST['description']);

When I bring it out to display it, I use this

<?php echo nl2br($description); ?>

 

When viewing the description, this is what it shows

 

After squandering an opportunity to wrap up the NFC North title on their home field a week ago, the Minnesota Vikings have been given a second chance. To realize that goal, however, they\\\'ll have to knock off the team with the best record in the conference. The Vikings will try once again to punch their ticket into the postseason when the defending world champion New York Giants invade the Metrodome for this Sunday\\\'s regular-season finale. New York owns the NFL\\\'s ninth-best rushing defense (94.9 ypg) but surrendered 158 yards and four touchdowns via the ground to the physical Panthers in Week 16, with Carolina\\\'s DeAngelo Williams becoming the second back to eclipse 100 yards on the Giants this year. The team is battling some health issues up front, as sturdy tackle Fred Robbins (33 tackles, 5.5 sacks) is dealing with a jammed shoulder and may be held out of the finale. The three-man linebacking corps lacks a standout, save for middle linebacker and leading tackler Antonio Pierce (91 tackles, 1.5 sacks). There\\\'s a chance the Giants will be without a key member of the secondary for Sunday\\\'s matchup as well, with starting cornerback Aaron Ross (52 tackles, 3 INT) having suffered a concussion against the Panthers. If the second-year pro can\\\'t go, Kevin Dockery (36 tackles, 1 INT, 9 PD) will likely be slotted into a greater role for a defense that is allowing just 194.7 passing yards per game (7th overall). New York has two quality pass-rushing ends in Pro Bowler Justin Tuck (65 tackles, 12 sacks) and Mathias Kiwanuka (48 tackles, 8 sacks), but the pair will be chasing a very mobile quarterback in Jackson (143 rushing yards), who had a personal-best 76 yards on eight scrambles against the Falcons.\\r\\n\\r\\n \\r\\n\\r\\nThe Giants\\\' powerful ground attack will be going up against a Minnesota defense that is yielding a league-low 73 rushing yards per game but will be without Pro Bowl tackle Pat Williams (44 tackles, 1 sack) for a second straight week due to a fractured shoulder blade. The Vikings were able to withstand the loss of the accomplished stopper last week, however, as the club held Atlanta\\\'s Michael Turner, the NFL\\\'s second-leading rusher, to a pedestrian 70 yards on 19 carries. Williams is one of four Minnesota defenders named to this year\\\'s Pro Bowl, along with fellow tackle Kevin Williams (57 tackles, 8.5 sacks), end Jared Allen (50 tackles, 14.5 sacks) and cornerback Antoine Winfield (88 tackles, 2 INT, 2 sacks). With New York\\\'s pass protection having been an issue as of late, Coughlin may be taking somewhat of a risk in letting Manning face a Vikings\\\' squad that has compiled 43 sacks on the year. Allen\\\'s 57 1/2 sacks since 2004 is the most of any NFL player over that span, while counterpart Ray Edwards (50 tackles, 5 sacks) took down the Falcons\\\' Matt Ryan twice in last week\\\'s loss. Winfield and four-time Pro Bowl safety Darren Sharper (63 tackles, 1 INT) are the headliners of a secondary that helped limit Atlanta to a mere 124 net passing yards this past Sunday.\\r\\nTAKE THE UNDER 42 POINTS

 

How can I get this to show properly?

 

Link to comment
Share on other sites

When you look directly in the database, there should be no (zero) escape \ characters (unless you deliberately have a \ as part of your data.)

 

You likely have magic_quotes_gpc set to ON and it is escaping the incoming data from your form. You are adding more escape characters with the mysql_real_escape_string() function, and you likely have magic_quotes_runtime set to ON, which will cause escape characters to be added when you retrieve the data from the database.

 

If magic_quotes_gpc is ON (you should turn it off if you can, it can be turned off on a PHP_INI_PERDIR basis), you must first use stripslashes() on the data before you use mysql_real_escape_string() and you should use set_magic_quotes_runtime() to turn off the magic_quotes_runtime setting.

Link to comment
Share on other sites

I checked with phpinfo()

magic_quotes_gpc Off Off

magic_quotes_runtime Off Off

 

I changed the insert to this

$description = stripslashes(mysql_real_escape_string($_POST['description']));

 

Now, it no longer shows the \, but it don't keep the the paragraphs and lines break, just one very long pragraph

 

 

I just checked the database, and the paragraphs and break were not kept when inserting.

This is just a simple textarea, so how would I go about keep the paragraphs and line breaks?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.