SieRobin Posted September 19, 2006 Share Posted September 19, 2006 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 tus?"[/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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/ Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 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 Offphp_flag magic_quotes_runtime Offphp_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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94745 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94747 Share on other sites More sharing options...
Destruction Posted September 19, 2006 Share Posted September 19, 2006 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 helpsDest Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94750 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [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 helpsDest[/quote]I've tried this, sorry it doesn't work :[ Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94752 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94754 Share on other sites More sharing options...
Destruction Posted September 19, 2006 Share Posted September 19, 2006 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] insteadDest Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94756 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [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] insteadDest[/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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94757 Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 SieRobin have you posted your code yet which I requested? :) Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94758 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [quote author=wildteen88 link=topic=108657.msg437350#msg437350 date=1158685174]SieRobin have you posted your code yet which I requested? :)[/quote]Yes, it's right above you in the code boxes. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94765 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94770 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Share Posted September 19, 2006 regex? like str_replace, and other things?? That might work have you thought of that. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94773 Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 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 Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94774 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94779 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [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 :PIf you're speaking of something else, please elaborate, I'm brain dead. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94780 Share on other sites More sharing options...
Ninjakreborn Posted September 19, 2006 Share Posted September 19, 2006 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.nl2brThen 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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94786 Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94790 Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-94882 Share on other sites More sharing options...
SieRobin Posted September 20, 2006 Author Share Posted September 20, 2006 Anyone have a clue, or am I going to have to suffer? lol. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95033 Share on other sites More sharing options...
neylitalo Posted September 20, 2006 Share Posted September 20, 2006 Have you tried the php_flag suggestions made by wildteen, in your .htaccess files? I have this sneaking suspicion that it'll work beautifully... Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95108 Share on other sites More sharing options...
SieRobin Posted September 20, 2006 Author Share Posted September 20, 2006 I checked my .htaccess file, and those aren't even an option, then again .htaccess doesn't even take an entire page up, it's pretty much small, and contains no more than 4-5 different options to change, would you like me to paste that here? Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95340 Share on other sites More sharing options...
wildteen88 Posted September 20, 2006 Share Posted September 20, 2006 You add them into the htaccess file. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95346 Share on other sites More sharing options...
SieRobin Posted September 20, 2006 Author Share Posted September 20, 2006 Ok, exactly what you typed before I put in there? Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95357 Share on other sites More sharing options...
SieRobin Posted September 20, 2006 Author Share Posted September 20, 2006 Hmmn, I put that in there, but now I'm getting a 500 Internal Server Error. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95363 Share on other sites More sharing options...
wildteen88 Posted September 20, 2006 Share Posted September 20, 2006 You just add the following:[code]php_flag magic_quotes_gpc Offphp_flag magic_quotes_runtime Offphp_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. Quote Link to comment https://forums.phpfreaks.com/topic/21298-rn-what-the-heck/#findComment-95364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.