Pisano u PHP
Sa ukusom PHP-a :)
Ako vam ikada zatreba TL sa tvitera u PHP verziji, tu je. Potrebno je samo da je SimpleXML instaliran na serveru.
<?php
// Init (Pozivanje $param1 = username sa twittera, $param2 = koliko statusa)
getTwitterStatus('miff78',20);
/*
* $uid = Twitter username // string
* $l = Limit, koliko statusa da se prikazu // int
* return: Statuse
* */
function getTwitterStatus($uid,$l){
$url = "http://twitter.com/statuses/user_timeline/$uid.xml?count=$l";
$xml = simplexml_load_file($url) or die('Nisam uspeo da se ucitam fajl!');
echo '<ul>';
foreach($xml->status as $status){
$text = findTw($status->text);
echo '<li>'.utf8_decode($text).'</li>';
}
echo '</ul>';
}
/*
* $s = Teks iz kojeg treba da se zamene @User i #Hashtag sa aktuelnim linkovima // string
* return: obradjeni tekst
* */
function findTw($s) {
$s = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" >\\2</a>", $s);
$s = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" >\\2</a>", $s);
$s = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" >@\\1</a>", $s);
$s = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" >#\\1</a>", $s);
return($s);
}
?>
Dok ne sredim ovaj prikaz coda, evo zip fajla.
PS. RegEX je mozda mogao bolje, zato nemoj odma neko da me napljuje nego neka napise u komentar :)




Budi prvi i
Ostavi komentar