I have a form where an information could b pasted. In order to preserve paragraph and line breaks I encode it before storing in my db like this:
if($POST["field_data"]) $myData=urlencode($POST["field_data"]); else $myData=$field_data;
When I retreive it, I decode it to get a regular HTML output:
$field_data = $dataFromDB ; $field_data= str_replace("%0D%0A", "<br>", $field_data);
Two questions:
Is this the best way of doing it?
When I have appostrophies in test like John's my data gets encoded and stored as John\'s and everytime I edit this text it keeps adding the escape character: John\\'s. How do I deal with that?
$field_data= str_replace("%0D%0A", "<br>", $field_data); Is this the best way of doing it?
$field_data= str_replace("%0D%0A", "<br>", $field_data);
I think that
$field_data=urldecode($field_data);
may be better for you.
To get rid of slashes, do this:
$field_data=stripslashes($field_data)
Perfect!
Does everything now work ok? If so, could you mark the threat resolved?