tidus97 Posted January 21, 2009 Share Posted January 21, 2009 hey guys. i posted about filtering out text and making it safe for input before and came up with this: function cleanupForStorage($x,$inExep=null){ $x = mysql_real_escape_string($x); $x = strip_tags($x,$inExep); return $x; } function cleanupForOutput($x,$exep=null){ $order = array('\r\n' , '\n', '\r'); $x = str_replace($order, '<br />', $x); $x = stripslashes($x); return $x; } $string = '<b>Hello, World!</b>""""""" do <i>you</i> like\hate slashes? and these "quotes"? what about new lines'; $string=cleanupForStorage($string,'<b>'); echo "This is for storage: ".$string."<br />"; $string=cleanupForOutput($string); echo "This is for output: ".$string."<br />"; what i do to put text into a DB is use a form to post it over to another php file that does the job. but for some reason, when i use the clean up for storage function, breaks are replaced by spaces and not '\r\n' , '\n' or '\r' and so i cant turn them into <br />'s. its not the functions, because i echo the posted text right away in the next php fle and the line breaks are gone. Link to comment https://forums.phpfreaks.com/topic/141747-solved-post-text-looses-line-breaks/ Share on other sites More sharing options...
sasa Posted January 21, 2009 Share Posted January 21, 2009 change line $order = array('\r\n' , '\n', '\r'); to $order = array("\r\n" , "\n", "\r"); or use nl2br() function Link to comment https://forums.phpfreaks.com/topic/141747-solved-post-text-looses-line-breaks/#findComment-742084 Share on other sites More sharing options...
tidus97 Posted January 21, 2009 Author Share Posted January 21, 2009 nl2br worked wonders. Link to comment https://forums.phpfreaks.com/topic/141747-solved-post-text-looses-line-breaks/#findComment-742113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.