开发者

Posting to twitter from file

I have such php script to post to twitter from file:

    function win2utf($s)  {  
       for($i=0, $m=strlen($s); $i<$m; $i++) { 
               $c=ord($s[$i]); 
               if ($c<=127) {$t.=chr($c); continue; } 
               if ($c>=192 && $c<=207)    {$t.=chr(208).chr($c-48); continue; } 
               if ($c>=208 && $c<=239) {$t.=chr(208).chr($c-48); continue; } 
               if ($c>=240 && $c<=255) {$t.=chr(209).chr($c-112); continue; }

               if ($c==184) { $t.=chr(209).chr(209); continue; };
               if ($c==168) { $t.=chr(208).chr(129);  continue; };
        }
   return $t;
} 

require_once 'options.php';     
require_once 'twitteroauth/twitteroauth.php'; 
set_time_limit(0);  
$connection = new TwitterOAuth($options['CONSUMER_KEY'], $options['CONSUMER_SECRET'], $options['OAUTH_TOKEN'], $options['OAUTH_SECRET']); 
$connection->format = 'xml';
$lines = file(ROOT.'inc/posts.txt');
$index = mt_rand(0, count($lines)-1); 
$status  = win2utf($lines[$index]); 
$connection->post('s开发者_如何转开发tatuses/update',   array('status'=>$status));

How should I improve this script to remove from file messages which I've posted already?


The best way would be to move the already tweeted lines onto a different file. Then one file will have all the tweeted lines and one file will have the lines that is yet to be tweeted.

Your function's readability isn't very great by the way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜