Why not use the addslashes and stripslashes functions, instead?
http://uk2.php.net/manual/en/function.addslashes.php
http://uk2.php.net/manual/en/function.stripslashes.php
Also, bear in mind that (to quote the manual):
The PHP directive
magic_quotes_gpc is on by default, and it essentially runs addslashes() on all GET, POST, and COOKIE data. Do not use addslashes() on strings that have already been escaped with
magic_quotes_gpc as you'll then do double escaping. The function
get_magic_quotes_gpc() may come in handy for checking this.
Take it easy,
Dan