I have a javascript rich page that is passing a large JSON formatted to php to be put in a MySQL database. The data in the JSON includes user submitted strings, and will include strings containing basic html (<a>, <strong> etc.).
The issue I am having is when a string containing a ' quotation mark is escaped, I cannot strip the slashes, leading to compounding escapes like
<a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'example.com\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'></a>
Every time the user saves this is compounded, severely bloating the database field.
My string conversion to insert data into MySQL is :
$correspondenceArray = base64_encode(json_encode($_POST['saveArray']['correspondenceObject']));
And to get data back is:
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$correspondenceJSON = stripslashes_deep(json_decode(base64_decode($resultArray['correspondence_array']), true));
From what I have done my intent is to strip the slashes on the data coming out of the database so the javascript has the unescaped data
Edit
I realise json_encode($a,JSON_HEX_QUOT) would possibly help, but the server I'm running has PHP 5.2.16 so that feature isn't available)
magic_quotes_gpc()turned on? Those'll litter slashes all over your data, and the option should be turned OFF.mysql_real_escape_string()so it should be a fairly safe switch