Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  17] [ 5]  / answers: 1 / hits: 22802  / 14 Years ago, mon, october 25, 2010, 12:00:00

So, when I save the data into database, PHP will add a on single or double quotes. That is good.



However, when data is passed back to the client using json_encode(); TEXT like McDonald's is STORED as McDonald's in the DB but once passed back from PHP to js, it will be encoded as McDonald's



Since I'm using jQuery, is there any plugin to easily do that? or any function I should use to strip the slashes correctly? obviously, if there is case like \\s, the function should return s. :)



Sorry guys. I think I made my question too complicated. How about I make it simpler..



If I have a javascript variable:



var abc = McDonald's;
var bcd = I need a slash \ ;
var cde = save the double quote ;


how can I strip the ' ? what the regex I should use?


More From » jquery

 Answers
8

Use: http://au.php.net/manual/en/function.mysql-real-escape-string.php before storing into database.



Use a custom function like this before writing onto any user interface:



function unescape($string)
{

$search = array(\x00, \n, \r, \x1a);

$replace = array(x00,n, r, x1a);

$retString = str_replace($search, $replace, $string);

$search = array(', '\'.'');

$replace = array( ', '',);

$retString = str_replace($search, $replace, $retString);

$search = array(\\);

$replace = array( \);

$retString = str_replace($search, $replace, $retString);

return $retString

}

[#95191] Thursday, October 21, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damiondenzelc

Total Points: 268
Total Questions: 116
Total Answers: 116

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;