Jump to content


Photo

RN!? WHAT THE HECK?


  • Please log in to reply
35 replies to this topic

#1 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 04:34 PM

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.

"Do you have anymore tu
s?"


Instead of.

"Do you have anymore turns?"

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

"Hey, did you hear about that awesome new game?rnrnIt's pretty cool."

Instead of.

"Hey did you hear about that awesome new game?

It's pretty cool."


So what exactly do I have to do, to fix this? Because I think I'm going to have a brain aneurism, lol.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 04:44 PM

Do you have a setting called magic_quotes_gpc pr magic_quotes_runtime or magic_quotes_sybase 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:
php_flag magic_quotes_gpc Off
php_flag magic_quotes_runtime Off
php_flag magic_quotes_sybase Off

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.

#3 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 04:46 PM

I believe yes I can use the .htaccess files, it's just a matter of finding them lol.

And yes I'll post that in just a second.

#4 Destruction

Destruction
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 19 September 2006 - 04:49 PM

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

#5 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 04:49 PM

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


I've tried this, sorry it doesn't work :[

#6 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 04:51 PM

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");
	  }

$postt shows as.

$postt=$_POST['postt'];

There ya go, lol.

#7 Destruction

Destruction
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 19 September 2006 - 04:52 PM

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
[p]
or
[br]
and have the code filter and replace those as
<br/>
instead

Dest

#8 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 04:56 PM

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

[p]
or
[br]
and have the code filter and replace those as
<br/>
instead

Dest


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.

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 04:59 PM

SieRobin have you posted your code yet which I requested? :)

#10 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 05:04 PM

SieRobin have you posted your code yet which I requested? :)


Yes, it's right above you in the code boxes.

#11 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 05:10 PM

Oh sorry forgot the other part, lol

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>";


#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 September 2006 - 05:13 PM

regex? like str_replace, and other things??  That might work have you thought of that.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#13 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 05:13 PM

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!

#14 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 05:21 PM

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!


Just posted the rest, and yeah I'm not THAT advanced with PHP, but I know most of the ins and outs.

#15 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 05:21 PM

regex? like str_replace, and other things??  That might work have you thought of that.


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.

#16 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 September 2006 - 05:31 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#17 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 05:37 PM

Businessman read the 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.

#18 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 19 September 2006 - 07:41 PM

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.


Thank you lol.

#19 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 20 September 2006 - 02:05 AM

Anyone have a clue, or am I going to have to suffer?  lol.

#20 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 20 September 2006 - 05:46 AM

Have you tried the php_flag suggestions made by wildteen, in your .htaccess files? I have this sneaking suspicion that it'll work beautifully...
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users