キーワードでつぶやきを検索

<?php
error_reporting(0);

$key     = 'あすか';
$rep_key = '<b>あすか</b>';
$lng     = 'ja';
$cnt     = 50;
$url     = 'http://search.twitter.com/search.json';
$params  = http_build_query(array('q' => $key, 'lang' => $lng, 'rpp' => $cnt));
$results = json_decode(file_get_contents("$url?$params"), true);
$res     = $results[results];

print <<< EOF
<table width=600>
  <tr>
    <td colspan="2"><hr></td>
  </tr>
EOF;

foreach ($res as $i) {
//echo "<tr><td colspan=2>";
//echo "<pre>";
//print_r($i);
//echo "</pre>";
//echo "</td></tr>";


	$val = $i["text"];
	$val = ereg_replace("(http)(://[[:alnum:]\S\$\+\?\.-=_%,:@!#~*/&]+)","<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",$val);
//	$val = ereg_replace("(@)([[:alnum:]\S\$\+\?\.-=_%,:@!#~*/&]+)","<a href=\"http://twitter.com/\\2\" target=\"_blank\">\\1\\2</a>",$val);
	$val = ereg_replace("(@)([[:alnum:]\S\$\+\?\.-=_%,@!#~*/&]+)","<a href=\"http://twitter.com/\\2\" target=\"_blank\">\\1\\2</a>",$val);
	$val = ereg_replace("(>)(http://twitpic.com/)([[:alnum:]\S\$\+\?\.-=_%,:@!#~*/&]+)(</a>)","><img src=\"http://twitpic.com/show/mini/\\3\" /></a>",$val);
	$val = ereg_replace($key,$rep_key,$val);
	
	$img = $i["profile_image_url"];
	
	$usr = $i["from_user"];
	$uid = $i["id_str"];
	$dat = date("Y年m月d日H時i分", strtotime($i["created_at"]));
	
print <<< EOF
  <tr>
    <td rowspan="2"><img src="{$img}"></td>
    <td>{$val}</td>
  </tr>
  <tr>
    <td><a href="http://twitter.com/{$usr}/status/{$uid}" target="_blank">{$dat}</a></td>
  </tr>
  <tr>
    <td colspan="2"><hr></td>
  </tr>
EOF;

}

echo "</table>";