1

我的部分PHP代码包括以下URL字符串的构造:

$msg = $_REQUEST["msg"];
$content =  'action=sendmsg'. 
                '&user='.rawurlencode($username). 
                '&password='.rawurlencode($password). 
                '&to='.rawurlencode($destination). 
                '&text='.rawurlencode($msg);

$msg碰巧包含撇号时,它会以"\'".

我需要做什么来确保反斜杠没有被插入PHP

4

3 回答 3

3

您可能想查看stripslashes:http://php.net/manual/en/function.stripslashes.php

于 2013-03-11T04:07:51.700 回答
2

假设您要发送$content变量而不是仅仅剥离反斜杠,请考虑使用urlencode()而不是rawurlencode(). 此外,您可以对$content变量使用该函数一次。

$content = urlencode($content);

更新:两者都urlencode可能rawurlencode不适合您的情况。你为什么不直接发送$content没有 URL 编码?您如何发送我们的查询字符串?如果您使用 cURL,则不需要对参数进行编码。

于 2013-03-11T04:09:55.070 回答
1

你可以试试

  1. 斜线
  2. 或将字符串放入 "" 并在您想要的位置添加 '。
于 2013-03-11T05:43:23.493 回答