Jump to content

[SOLVED] post text looses line breaks


tidus97

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.