John
John

Reputation: 4944

After mysql_real_escape_string, apostrophes showing up in Twitter with a preceding backslash

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"));

Upvotes: 0

Views: 302

Answers (2)

Michael Madsen
Michael Madsen

Reputation: 55009

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.

Upvotes: 3

rabudde
rabudde

Reputation: 7722

Perhaps magic_quotes are set to on in PHP conf? See manual

You can do also

$comment = mysql_real_escape_string(stripslashes($_POST['comment']));

Upvotes: 2

Related Questions