tags:

views:

549

answers:

5

Hello all,

I pass text from a POST variable from a form on my site to Twitter and I save this message on my own site. When I view the entry on my site it is absoultly fine. However, in some cases when there is an apostrophe in the message twitter updates the status of a user but escapes the apostrophes and this can be seen on the users status!

This doesn't happen when I update my twitter status on the twitter site. So I am wondering is there a way I need to pass text to twitter?

I currently do this and I make use of this awesome Twitter class. http://github.com/jmathai/twitter-async/tree

$success = $twitterObj->post_statusesUpdate(array('status' => $_POST['message'].$URL.$key));

In addition, passing URLs to twitter use to automatically link the URL but now this just appears as text?

Has twitter made changes in the past month that would cause the above to happen? If not how can I overcome this?

Thanks all

EDIT

More Code:

function tweetit(){
    global $URL;
    global $key;

    include './twitter/EpiCurl.php';
    include './twitter/EpiOAuth.php';
    include './twitter/EpiTwitter.php';

    $consumer_key = 'hidden';
    $consumer_secret = 'hidden';

    $twitterObj = new EpiTwitter($consumer_key, $consumer_secret);

    $twitterObj->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

    $success = $twitterObj->post_statusesUpdate(array('status' =>  $_POST['message'].' '.$URL.$key));

    return $success->response['id']; 
}
A: 

You can use htmlentities function for this.

$success = $twitterObj->post_statusesUpdate(array('status' => htmlentities($_POST['message']).$URL.$key));

Or htmlspecialchars:

$success = $twitterObj->post_statusesUpdate(array('status' => htmlspecialchars($_POST['message']).$URL.$key));
Cesar
Just tried the htmlspecialchars - but it didn't work as all characters such as doubles quotes ans single quotes are still being escaped!
Abs
And the addslashes function? don't resolve too?
Cesar
Just tried that, it actually added twice as many back slashes as before! :(
Abs
Ok, then with urlencode function? because if class uses url parameters to send can be this! :)
Cesar
This didn't work either as I got: "Funny+time%5C%27s+lol" when I typed in "Funny time's lol" - this is very strange. I can't figure out if the problem is how I am passing my string or the string itself??
Abs
+1  A: 

Are you using the latest version? Not sure what the problem is since one of the unit tests for the library puts in single quotes (among other random characters).

http://github.com/jmathai/twitter-async/blob/master/tests/EpiTwitterTest.php#L90

Jaisen
Thanks for your reply Jaisen. I was not using the latest from Git - but I am now and did another test and I seem to get the same thing. I am sure there is nothing wrong with your code as it is probably working for your guys fine when you use single quotes. I am sure its not twitter, so whats left is me and my code! I have edited my question with how I use your classes. Maybe there is something wrong there? If not, what else could I try?
Abs
Repped you for actually writing the classes - not enough of a thanks but a good gesture at the very least! :)
Abs
Heh, gracias. (need 15 chars)
Jaisen
+2  A: 

Sounds like your php config has magic_quotes_gpc turned on, which automagically calls addslashes on all input (e.g., your POST values). I'd read up on addslashes/stripslashes in the php manual.

CapnNefarious
You sir are a genius. I used stripslashes on what I passed to twitter and it works great.
Abs
A: 

After you receive the post but before you send it off via the curl, remove slashes with stripslashes

urlencode(stripslashes($posted_status_update));

Roger Dodger
A: 

I had the same problem. Twitter behaves differently if called with www.twitter.com instead of twitter.com. This is a known bug.

http://code.google.com/p/twitter-api/issues/detail?id=890&can=1&q=www&colspec=ID%20Stars%20Type%20Status%20Priority%20Owner%20Summary%20Opened%20Modified%20Component

underdog