PHP:twitterの検索結果のRSSを取得して表示させる | Re:
これをパクって参考にして、twitterから該当の単語を取得できるようにはなりました。
「琉大」で検索した画面です。
(おいおい、琉大祭って今週なのかよ…知らなかった…)
ソース(上のページとほぼ同じ。変えたのは表示数とmb_convert_encodingをutf8にしただけ。)
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <?php $rss = simplexml_load_file('http://search.twitter.com/search.atom?q=琉大'); $i = 0; foreach ($rss->entry as $entry) { if(++$i>100) break; //表示数 $attr=$entry->{'link'}->attributes(); echo "<li>"; echo '<a href="'.$attr['href'].'">'.convert($entry->author->name).'</a><br />'; echo convert($entry->content); echo "</li>"; } function convert($str) { return mb_convert_encoding($str,"utf8"); //文字コードをutf8に } ?> </body> </html>