Post to Twitter PHP Function (915 bytes, 309 hits)

Looking to Tweet from PHP? This little function will do exactly that. Simply supply a username, password and Tweet, and thanks to CURLs black magic your message will be Tweeted. You can also specify which format you would like the response in – either JSON or XML, with JSON being the default.

<? function tweet($username, $pword, $status, $format='json') {
$ch = curl_init(); // init curl
curl_setopt($ch, CURLOPT_URL, "http://twitter.com/statuses/update.".$format);
curl_setopt($ch, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$pword");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$bf = curl_exec($ch); // execute curl call
curl_close($ch); // close curl handler
// Return true or false demending on results
return $bf;
} ?>

Using the PHP to Twitter function
echo tweet('TwitterUSERNAME','Password','Rocking the PHP-To-Twitter function by @brandoncorbin');

  Post to Twitter PHP Function (915 bytes, 309 hits)