Хорошо, так что я наткнулся на этот пост и боролся с ответами ... но вот мое решение ... работает отлично ... Единственная проблема, которую я вижу, заключается в том, что она основана на получении RSS-канала, что довольно симпатично для Twitter стремится избавиться от - но для простого решения это работает очарование.
function twitter_status(){
$twitter_name = "YOUR_TWITTER_USERNAME";
$myFile = "http://api.twitter.com/1/statuses/user_timeline.rssscreen_name=".$twitter_name;
$dom = new DOMDocument();
$dom -> load($myFile);
$items = $dom->getElementsByTagName('item');
$max_items = 1; // Number of tweets to return.
$count = 0;
foreach ($items as $item) {
// Select all the elements in the XML document named "Description"
// The different elements available are Title, Description, pubDate, guid, link and twitter:source
// You can find this out by opening the link to your twitter rss feed
$tweets = $item->getElementsByTagName('description');
$tweet_string = $tweets->item(0)->nodeValue;
$tweet_string = substr($tweet_string,strpos($tweet_string,":")+2);
$tweet_date = $item->getElementsByTagName('pubDate');
$tweet_date = $tweet_date->item(0)->nodeValue;
$tweet_date = substr($tweet_date,0,16); // Get rid of the excess times at the end of the date
echo ("<li class='timestamp tweet_".$count."'>Posted ".$tweet_date."</li><li class='tweet tweet_".$count."'>".makelink($tweet_string)."</li>");
$count = $count+1;
if ($count>=$max_items){ break; }
}
}
function makeLink($string){
// Function to convert url to a link
/*** make sure there is an http:// on all URLs ***/
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
/*** make all URLs links ***/
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</A>",$string);
/*** make all emails hot links ***/
$string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$string);
return $string;
}
Так что это моё решение, однако оно довольно специфично для того, что я хотел - но большинство из вас может решить это с надеждой и внести необходимые коррективы. Я не особо хороший программист, поэтому, если я допустил явные ошибки или смог улучшить этот скрипт, я был бы признателен.