Get Twitter Status with JSON

13 08 2010

$url = 'http://twitter.com/statuses/user_timeline/phoenixblue.json?count=10';
$url_content= file_get_contents($url,0,NULL,NULL);
$statuses = json_decode($url_content);
//var_dump($statuses);
echo $statuses[0]->text;





Truncate Whole Words

1 08 2010

function trunc($phrase, $max_words)
{
$phrase_array = explode(' ',$phrase);
if(count($phrase_array) > $max_words && $max_words > 0) {
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...' ;
}
return $phrase;
}





Get Twitter Statuses With curl()

1 08 2010

function get_twitter_status() {
  $status_list = array();
  $c = curl_init();
  curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/phoenixblue.xml?count=10");
  // count = number of statuses to grab
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($c, CURLOPT_CONNECTTIMEOUT, 20);
  curl_setopt($c, CURLOPT_TIMEOUT,5);
  $src = curl_exec($c);
  $xmlList = new SimpleXMLElement($src);
  foreach($xmlList->status as $xml) {
    $text = (string)$xml->text;
    $status_list[] = $text;
  }
  if(count($status_list) $status_list[] = $xmlList->error;
  return $status_list;
}





Change Last Modified Header

1 08 2010

At the top of the file in php tags:

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");