James Cridland

Twitter broadcaster

As documented in this blog entry, this is a way of broadcasting messages to Twitter. If you've your own shortcode. You don't? Oh.

<?

// This expects a call looking like thisscript.php?text=This+is+the+message

$text=trim($_REQUEST['text']);

if (
strlen($text)>1) {

$text=trim(substr($text,8));
if (
strlen($text)>120) { $text substr($text,0,116)."... "; }
$text=$text." [Reply: 81xxx KEYWORD %2B msg]"// Change how to reply
send_to_twitter($text,"twitter_username","twitter_password"); // Change your username/password!

}


function 
send_to_twitter($status,$username,$password) {

        
//this code based on http://www.morethanseven.net/posts/posting-to-twitter-using-php/
        //

        
$url 'http://twitter.com/statuses/update.xml';
        
$curl_handle curl_init();
        
curl_setopt($curl_handleCURLOPT_URL"$url");
        
curl_setopt($curl_handleCURLOPT_CONNECTTIMEOUT2);
        
curl_setopt($curl_handleCURLOPT_RETURNTRANSFER1);
        
curl_setopt($curl_handleCURLOPT_POST1);
        
curl_setopt($curl_handleCURLOPT_POSTFIELDS"status=$status");
        
curl_setopt($curl_handleCURLOPT_USERPWD"$username:$password");
        
$buffer curl_exec($curl_handle);
        
curl_close($curl_handle);

}


?>

Download this code