Nolongerused3921 Posted January 22, 2007 Share Posted January 22, 2007 The title says it all, for some reason mysql_real_escape_string breaks \n... Even with stripslashes().How do I fix this...? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 you say "breaks" - but you dont give an example mentioning who/how/why/what/when etc."Breaks" is quite a general term here - can you be more specific, especially with the results you're getting? Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 [quote]Fixed's 'should''' be ''' workingrnrnrnrnYAY![/quote]Was inserted as[quote]Fixed's 'should''' be ''' workingYAY![/quote]Or something similar... I had just fixed my $_POST import function (To parse it all before a user has access to it), and it turns out it wasn't calling mysql_real_escape_string, so I added it and now er... It seems to have broken the ability for new lines to work.Portion of the $_POST import function (The only part of it that pertains to this, the entire function is over 70 lines)[code]<?php if (get_magic_quotes_gpc()) { $tmp_data = stripslashes($tmp_data); } if ($filter_type == 2) { $tmp_data = htmlentities($tmp_data); $tmp_data = mysql_real_escape_string(strip_tags(trim($tmp_data))); } elseif (!is_numeric($tmp_data)) { //Then we can finish this.. otherwise it should be safe if it's just a number.. $tmp_data = htmlspecialchars($tmp_data, ENT_QUOTES); $tmp_data = mysql_real_escape_string(strip_tags(trim($tmp_data))); }?>[/code]My content/bbcode parsing (The part that is called in order to strip slashes, convert nl2br, convert bbcode, etc.):[code]<?php function bbcode($data, $bbcode_on = TRUE){ $db = $this->db_class; if ($db->is_connected() == NOT_CONNECTED){ $db->connect(); } $data = htmlspecialchars($data); $data = stripslashes($data); $pattern = array(); $replacement = array(); $bbcode = $GLOBALS['bbcode']; if ($bbcode_on = TRUE) { for ($i = 0; $i != count($bbcode); $i++) { if ($bbcode[$i][type] == "bbcode") { array_push($pattern,$bbcode[$i][pattern]); array_push($replacement,$bbcode[$i][replacement]); } if ($bbcode[$i][type] == "smiley") { $data = str_replace($bbcode[$i][pattern], "<img src='".$this->rdir."images/smilies/".$bbcode[$i][replacement]."' />", $data); } } $data = preg_replace($pattern, $replacement, $data); } $data = str_ireplace(chr(10), "<br />\n", $data); nl2br($data); return $data; } function content($data, $bbcode_on = TRUE) { $data = html_entity_decode($data); $data = $this->bbcode($data, $bbcode_on); return $data; }?>[/code]All content is sent through content($data, TRUE/FALSE), and this is what is [b]now[/b] screwing it up, but prior to adding real_mysql_escape_string, it was working fine. Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Why was my post edited...? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 [quote]Why was my post edited...?[/quote]because i put [ code] [ /code] tags which makes things about 4,000,000 times easier to read. otherwise, nothing was changed. Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Okay thanks, but er... Is there an answer to my question? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 It looks fine. \r\n is the equivalent to a new line. Why do you say it's not working? Can you show a live example, not just copy and paste text? Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 It... Doesn't convert it to actual new lines, that quote I pasted was after it ran through content(), in an html area... As for showing a live example - it'd take me awhile, as I'm currently testing locally... Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 They look like new lines to me... Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Errr sorry about the confusion...[quote]Fixed's 'should''' be ''' workingrnrnrnrnYAY![/quote]Thats what the html output is, as in - what a person would see if they were viewing that article....What I actually wrote, and commited to the database was:[quote]Fixed's 'should''' be ''' workingYAY![/quote] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 You're probably calling stripslashes too many times. Take it out? Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 If I take it out, it just shows as \n\n\n\n\n... Its not parsing it for some reason Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Because those aren't new lines in HTML. Run it through nl2br. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 [url=http://www.php.net/nl2br]nl2br[/url]??[b]edit[/b]: pipped again ;) Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 I did run it through nl2br, look at the bottom of the bbcode function... :( Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 yes but you're not capturing its return. you need[code]$data = nl2br($data);[/code] Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Nope... Still not working, same output regardless of where $data = stripslashes($data); and $data = nl2br($date); are placed Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Okay you have to take OUT the stripslashes, and use nl2br. Not both. Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 I have taken out stripslashes altogether as well Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 was this: $data = nl2br($date) a typo in your post, or a typo in your code? [code]$data = nl2br($data);[/code] Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Yes it was a typo in the post... Too bad, I thought it was that simple :(And this may help a bit... The data from MySQL (Unedited, directly from phpmyadmin) :[quote]Wonder\r\n\r\n\r\n\r\n\r\n\r\nIf\r\n\r\n\r\nTHis\r\nREALLY\r\n\r\n\r\nWORKS\r\n\r\n!?[/quote](I wrote a new string to just test this and not stripping \')The html from the edit area:[code]<textarea name="content" cols="80" rows="20">Fixed \r\n\r\nit\r\n\r\nshould\r\n\r\n\r\n\r\nwork\r\n\r\n\r\n\r\n\r\nNOW!</textarea>[/code]From just printing the item:[code]Fixed \r\n\r\nit\r\n\r\nshould\r\n\r\n\r\n\r\nwork\r\n\r\n\r\n\r\n\r\nNOW![/code]The code to print it:[code=php:0]<?php print $parser->content($temp_data[content]); ?>[/code] Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Don't suppose anyone knows...? Was kind of hoping to figure this out so I could finish this up Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 ...<?php print nl2br($parser->content($temp_data[content])); ?>*shrug* Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Author Share Posted January 22, 2007 Nope :( nl2br is already ran in content function (Shown in my first post)... For some reason its taking \n as a literal string and completely ignoring it Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Okay but did you try what I posted, or just say no?What is $parser? It's probably something in there that's causing the problem then.I give up, good luck. Quote Link to comment 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.