在 mysql_real_escape_string 之后,撇号出现在 Twitter 中,前面带有反斜杠
在下面的代码中,第二行将 $comment
发布到 Twitter。
当下面的 $comment
中包含撇号时,它们在推文中的前面会带有反斜杠。如何去掉 Twitter 中的反斜杠?
$comment = mysql_real_escape_string($_POST['comment']);
$tweet->post("statuses/update", array("status" => "$comment $fullurl"));
In the code below, the second line posts $comment
to Twitter.
When $comment
below has apostrophes in it, they are preceded in the Tweet with a backslash. How can I get rid of the backslash in Twitter?
$comment = mysql_real_escape_string($_POST['comment']);
$tweet->post("statuses/update", array("status" => "$comment $fullurl"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有这些中都没有可见的 SQL,因此调用 mysql_real_escape_string 没有任何意义。事实上,既然你说你要在 Twitter 上发帖,我怀疑你这边根本是否涉及任何 SQL(至少这部分没有)。
转义应始终作为最后一件事进行,立即在 SQL 语句中实际使用变量之前进行,并且仅用于该 SQL 语句的上下文。如果您的
$tweet->post
函数也在您这边执行一些 SQL,请让该函数执行必要的转义。There's no SQL visible in all of this, so there is no point in calling
mysql_real_escape_string
. In fact, since you say you're posting to Twitter, I doubt there's any SQL involved at all on your side (at least not for that part).Escaping should always be done as the very last thing, immediately before actually using the variable in an SQL statement, and only for the context of that SQL statement. If your
$tweet->post
function does some SQL on your side as well, have that function do the escaping necessary.也许
magic_quotes
在 PHP conf 中设置为 on ?请参阅 手册您也可以这样做
Perhaps
magic_quotes
are set to on in PHP conf? See manualYou can do also