用于删除和添加回来的PHP函数?

I have a search form for finding restaurants. I got it handling apostrophe's just fine for the actual search, but when they're passed as \' into Javascript for mapping it's killing my maps.

Example: xml_searchresults.php?cityID=1&type=1&searchTerm=Sonny\'s Real Bit BBQ

For a simple fix, in PHP I'm trying to go from:

$searchTerm = "Sonny\'s Real Bit BBQ" (in the original PHP file)

Then replace the \' with [slashapostrophe]:

$searchTerm = "Sonny[slashapostrophe]s Real Bit BBQ" (to be fed to javascript)

and then replace the [slashapostrophe] back with \':

$searchTerm = "Sonny\'s Real Bit BBQ" (in the PHP generated XML map marker file)

I tried str_replace but the quotes and slashes confuse it. Thanks!

php function addslashes() to quote string with '\' and stripslashes() to remove extra '\' symbols ( to unquote quoted string)

You are looking for stripslashes(): http://php.net/manual/en/function.stripslashes.php