Jump to content

RN!? WHAT THE HECK?


SieRobin

Recommended Posts

Ok here's the problem, I've posted about this before, but the problem was solved with a bad idea. The problem is, that on my forum, when you're writing your reply/thread post, I want the person to be able to just hit the enter key to line break when it shows the output on the actual forum itself. Now, when you do this, EVERY linebreak shows as "rn", whatever that's supposed to mean?

The solution I came up with was a str_replace just replacing "rn" with "\n", problem is, what if they use the word "turn" or "learn"? Well then it would output this.

[b]"Do you have anymore tu
s?"[/b]

Instead of.

[b]"Do you have anymore turns?"[/b]

Now if you don't use the str_replace and you use linebreaks, this is what happens.

[b]"Hey, did you hear about that awesome new game?[i]rnrn[/i]It's pretty cool."[/b]

Instead of.

[b]"Hey did you hear about that awesome new game?

It's pretty cool."[/b]

So what exactly do I have to do, to fix this? Because I think I'm going to have a brain aneurism, lol.
Link to comment
Share on other sites

Do you have a setting called [b]magic_quotes_gpc[/b] pr [b]magic_quotes_runtime[/b] or [b]magic_quotes_sybase[/b] enabled? If you do these could be why you are having this problem.

Can you use .htaccess files with your hosting account? If you can create a new or edit existing .htaccess file in the root of where your forum is located and add this to it:
[code]php_flag magic_quotes_gpc Off
php_flag magic_quotes_runtime Off
php_flag magic_quotes_sybase Off[/code]

Also could you post the code you use when you submit the reply/thread to the database aswell as the code you use when you get the code out of the database too.
Link to comment
Share on other sites

[quote author=Destruction link=topic=108657.msg437342#msg437342 date=1158684541]
If you have a textbox, a newline is added when return/enter is pressed.  To get it to display that in output you'll need to nl2br($output) the output ($output being whatever output variable you would be using).  This will convert any new line to <br/>

Hope this helps

Dest
[/quote]

I've tried this, sorry it doesn't work :[
Link to comment
Share on other sites

[code]elseif (isset($sthread)) {
if (empty($titlet)) {
print "<center><table class='table'><tr class='headline'><td align='center'>New Thread</td></tr>
<tr class='mainrow'><td align='center'>To post a new thread, you must have a title.<br>
<a href='forum.php?brd=$brd'>Back To Board</a></tr></td></table>";
} else {
print "<center><table class='table'><tr class='headline'><td align='center'>New Thread</td></tr>
<tr class='mainrow'><td align='center'>Your thread has been posted.<br>
<a href='forum.php?brd=$brd'>Back To Board</a></tr></td></table>";
mysql_query("INSERT f_thread set author='$userstats3[playername]', UID='$userstats3[ID]', title='$titlet', post='$postt', bname='$brd', timep='$nowtime'") or die ("Could not post reply");
  }[/code]

$postt shows as.

[code]$postt=$_POST['postt'];[/code]

There ya go, lol.
Link to comment
Share on other sites

[quote author=Destruction link=topic=108657.msg437348#msg437348 date=1158684779]
Sorry I meant to say textarea.  Which are you using for the entered text you're trying to break up?

Also, you could use a BBCode style solution where they could but [code][p][/code] or [code][br][/code] and have the code filter and replace those as [code]<br/>[/code] instead

Dest
[/quote]

I'm using a textarea, and I'd kinda like them to just be able to hit enter and it automates a linebreak for them.
Link to comment
Share on other sites

Oh sorry forgot the other part, lol

[code]elseif (isset($msg)) {
  mysql_query("UPDATE f_thread set views=views+1 where bname='$brd' AND ID='$msg'") or die("Could not log views");
      $post="SELECT * from f_post where bname='$brd' AND msg='$msg' order by ID ASC";
    $post2=mysql_query($post) or die ("Could not display threads");
print "<center><table class='ftable'><tr class='headline'><td colspan='2'><center>Forum</center></td></tr>
<tr class='mainrow'><td bgcolor='ababab' width='20%' rowspan='2' class='mainrowf'><a href='profile.php?id=$thread3[UID]'>";
if ($pstats3['uimage']=="") {
print "<img src='image.php?img=images/nophoto.jpg' border='0'><br>";
} else {
print "<img src='image.php?img=userimages/$pstats3[uimage]' border='0'><br>";
}
$newtext=wordwrap($thread3['post'], 83);
print "$thread3[author]</a><br>
Race: $pstats3[race]<br>Level: $pstats3[level]</td><td class='mainrowb'>$thread3[title]</td></tr>
<tr class='mainrow'><td class='mainrowf'><pre>$newtext</pre><br>";
if ($userstats3['ID']==$thread3['UID']||$userstats3['acctype']>2) {
print "<div align='right'>[<a href='forum.php?brd=$brd&msg=$msg&tquote=$thread3[ID]#bottom'>Quote</a>] [<a href='forum.php?brd=$brd&del=$thread3[ID]'>Delete</a>]</div>";
} else {
print "<div align='right'>[<a href='forum.php?brd=$brd&msg=$msg&tquote=$thread3[ID]#bottom'>Quote</a>]</div>";
}
print "<hr>$pstats3[quote]</td></tr>
<tr height='14' class='spacing'><td colspan='2'></td></tr>";[/code]
Link to comment
Share on other sites

Umm missed that! What code do you use to get the post out of the database when you display the post? The code you posted is fine. However I strongly suggesst you validate your user input. As at the moment your code is can be exploited with SQL Injection attacks, which can cause damage to your database!
Link to comment
Share on other sites

[quote author=wildteen88 link=topic=108657.msg437366#msg437366 date=1158685996]
Umm missed that! What code do you use to get the post out of the database when you display the post? The code you posted is fine. However I strongly suggesst you validate your user input. As at the moment your code is can be exploited with SQL Injection attacks, which can cause damage to your database!
[/quote]

Just posted the rest, and yeah I'm not THAT advanced with PHP, but I know most of the ins and outs.
Link to comment
Share on other sites

[quote author=businessman332211 link=topic=108657.msg437365#msg437365 date=1158685991]
regex? like str_replace, and other things??  That might work have you thought of that.
[/quote]

I was using str_replace lol, that's what I said in the post to begin with :P

If you're speaking of something else, please elaborate, I'm brain dead.
Link to comment
Share on other sites

Ok using regular expressions check for what you are looking for.  Which would be line breaks.  Then replace that with a <br /> so it appears that way in the browser(you can do this with new line to br.
nl2br
Then after that, also use regular expressions to check for occurences of words with rn or whatever problem you were having, make sure the text stays proper until output.
Link to comment
Share on other sites

[quote author=wildteen88 link=topic=108657.msg437382#msg437382 date=1158687433]
Businessman read the friggin first post of this thread. What is happening is newline characters are being displayed in the posts for his forum as rn or r or n. Which mean the characters are being escaped.
[/quote]

Thank you lol.
Link to comment
Share on other sites

You just add the following:
[code]php_flag magic_quotes_gpc Off
php_flag magic_quotes_runtime Off
php_flag magic_quotes_sybase Off[/code]
Into the htaccess file. Just copyu and paste in to the htaccess file Save. What this does is changed PHP configuration if magoc quotes is enabled.
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.