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?
mysql_real_escape_string($user_input)going into the DB andhtmlentities($db_output)going out to the client -- but this may not be considered 100% safe any more. Hopefully someone can give better advice.json_encodewill do).htmlspecialchars(). It is sufficient.htmlentities()because it is significantly more destructive to user input, without having any visible impact on the rendered page (as long as you match the page encoding). When I did some studying of hacking methods three years ago, I was appalled at the variety of unicode characters available to a determined hacker -- and I still don't understand how many of these techniques worked. And I'm still not 100% surehtmlentities()is safe, but I know it's safer thanhtmlspecialchars().htmlspecialchars()targets just the characters generally used for XSS. I think usinghtmlentities()will do the same, but just bloat the page using&#xx;style encoding for exotic characters, and most encoded stuff can be achieved by using UTF-8 as the character set.