Line breaks in Form Data

Status
Not open for further replies.

Adam01

New Member
Messages
114
Reaction score
0
Points
0
[solved]Line breaks in Form Data

As you can see here , the are no line breaks in the post, but i did post line breaks. How can you make it so you can make linebreaks.
 
Last edited:

Adam01

New Member
Messages
114
Reaction score
0
Points
0
Its not like that, its like what im doing now..

a line break like this when a user posts something.
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Looks like a custom forum?

Try something like this if the database has the new-line characters stored (meaning that it has the windows "you pushed enter" key in there; you'll know if this works):

$article=str_replace($emote_text,$emote_html,$r[4]);
$article=str_replace(array("\r\n", "\n\r", "\n", "\r"), "<br />", $article);

First line's something off an old version of my website, $r[4]'s the column in mysql that had the news. That entire first line could actually get erased (and I would, it's just there cause it's what originally sets $article).

Replace $article with your variable and you'll be ok - just be advised about that second line:

1) You'll notice it sets $article to a modified version of $article. If you wanna fix that, the one inside str_replace is the variable it's modifying, the one outside should be whatever variable you're going to use to display it on screen.

2) More for documentation purposes than anything, I pulled that off of some random php website. The \r and \n are apparently windows newline characters, and depending what system you were on when you wrote them, it'd leave both, one, or the other. So we're basically solving it by taking any combination of the two and replacing it with a line-break (like what GamingX said) :)

3) No credit needed cause I've no idea where I got it, but I know wherever I got it from didn't need credit either >_<


Lemme know if it works; pulled it straight out of my old news php file :)
 

Adam01

New Member
Messages
114
Reaction score
0
Points
0
wow, thats confusing, so...

before it submits the post to mysql , i would put this in:

Code:
$Message = $_POST['Message'];

$Message=str_replace($emote_text,$emote_html,$r[4]);
$Message=str_replace(array("\r\n", "\n\r", "\n", "\r"), "<br />", $Message); 

mysql_query("INSERT INTO Forums (Message...

Right?
 
Last edited:

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
wow, thats confusing, so...

before it submits the post to mysql , i would put this in:

Code:
$Message = $_POST['Message'];

$Message=str_replace($emote_text,$emote_html,$r[4]);
$Message=str_replace(array("\r\n", "\n\r", "\n", "\r"), "<br />", $Message); 

mysql_query("INSERT INTO Forums (Message...
Right?

Use this:

Code:
$Message = $_POST['Message'];
$Message=str_replace(array("\r\n", "\n\r", "\n", "\r"), "<br />", $Message); 
mysql_query("INSERT INTO Forums (Message...

That other line was in there cause on mine I had it as news.php; $emote_text had stuff like :) :( etc, all the text versions o fit, and the emote html replaced it with the emote image. You dun need that line cause this is for inserting into the database apparently :)

The line that I left there'll take any of those fancy newlines and make them breaks. That first one's not needed unless you really wanna make it complex ;)
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
do u know how to do it from a text area and also how to escape "\" because i think its bcoz of magic...!
 
Status
Not open for further replies.
Top