Originally posted by l008com:
that works for quotes but i need single quotes >'< and percent signs >%< and I think a few more for MySQL, but those three are the main ones. Thing is your code looks like someone leaned against their keyboard, so I don't really know how to add more types to it.
You can easily change Arkham's example to more suit your needs... The code is a little mysterious, but check this out, all you need to pay attention to in that code is this part:
echo 'hello, "bob", how are you?' | sed 's/
"/\\"/g'
The s/"/\\"/g tells sed to
substitute all instances of the character after the "/" with the character after the next "/", which would be
\\". The first backwards slash
escapes the next backwards slash will get printed to the shell and passed on uninterpretted with the
". The "g" after the next "/" tells sed to do this substitution globally, and not just on the first instance that it finds.
Basically, this will replace all double quote characters with a
\" so that by the time MySQL gets that string, it escapes the
" and sees the double quote as exactly that.
I hope you understood that... it's kinda hard to denote on a message board... Just remember that any backwards slashes you see are escaping some character... if there are two then the code is escaping the backward slash itself... now you can mod Arkham's code as such to work with single quotes:
Code:
echo 'hello, "bob", how are you?' | sed 's/\'/\\\'/g'
I can imagine how confused you must be, I was pretty confused just typing this post.
