I don't know why but it seems like wordpress is adding a second backslash when I'm using the following functions:
addslashes($str_with_single_quotes) addslashes(stripslashes($str_with_single_quotes)); esc_sql($str_with_single_quotes) str_replace("'", "/'", $str_with_single_quotes)
What I'm doing is that I'm fetching data from different API's and then converting those data to a json string so I can access them later on:
$item_data = array( 'item_title' => __(addslashes(stripslashes($item_name))), 'product_review' => __(addslashes(stripslashes($product_review))), 'freebase_text' => __(addslashes(stripslashes($freebase_result['text']))) ); $data = json_encode($item_data);
It doesn't seem like the localization function (
__()) is the one that's causing the problem since the problem is still there even I completely remove it.
I also tried
preg_replace_all but I got a fatal error that the function wasn't recognize. I also tried using
str_replace after the array was converted a json string but no luck.
I've run out of ideas on how to solve this problem. Simply using
json_encode without processing the strings doesn't actually do anything and the single quotes are left unescaped.
Magic quotes are also disabled:
magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off
Thanks in advance.