Revision: 40120
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 26, 2011 17:25 by kangcom
Initial Code
<FORM NAME=frm ACTION=search.php METHOD=POST> <INPUT TYPE=TEXT SIZE=20 NAME=q> <INPUT TYPE=SUBMIT VALUE=Search> </FORM> <? if($q != null) { $url = "http://search.twitter.com/search.json?q=".urlencode(iconv("euc-kr","utf-8",$q)); $cont = get($url); if($cont == null) { echo "no result"; exit; } // echo $cont; $idx = 0; $PROFILE_IMAGE_URL = "\"profile_image_url\":\""; $USER = "\"from_user\":\""; $ID = "\"id_str\":\""; $TEXT = "\"text\":\""; echo "<TABLE BORDER=0 WIDTH=500 STYLE=font-size:10pt;>"; while(($idx = strpos($cont,$PROFILE_IMAGE_URL,$idx))!=null) { $idx2 = $idx+strlen($PROFILE_IMAGE_URL); $idx3 = strpos($cont,"\"",$idx2); $image_url = substr($cont, $idx2, $idx3-$idx2); $idx4 = strpos($cont, $USER, $idx3); $idx5 = strpos($cont, "\"", $idx4+strlen($USER)); $user = substr($cont, $idx4+strlen($USER), $idx5-($idx4+strlen($USER)) ); $idx6 = strpos($cont, $ID, $idx5); $idx7 = strpos($cont, "\"", $idx6+strlen($ID)); $id = substr($cont, $idx6+strlen($ID), $idx7-($idx6+strlen($ID)) ); $idx8 = strpos($cont, $TEXT, $idx7); $idx9 = strpos($cont, "\"", $idx8+strlen($TEXT)); $text = substr($cont, $idx8+strlen($TEXT), $idx9-($idx8+strlen($TEXT)) ); // echo utf8_urldecode($text)."<br>"; echo "<TR><TD ALIGH=LEFT><IMG SRC=".$image_url."></TD>"; echo "<TD> writer : ".$user."<BR>"; echo utf8_urldecode($text)."</TD></TR>"; echo "<TR><TD HEIGHT=1 BGCOLOR=SILVER COLSPAN=2></TD></TR>"; ++$idx; } } // convert unicode to korean language function utf8_urldecode($str) { $str = str_replace("\\","%",$str); $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'UTF-8'); } // get web page function get($url) { $fp = fopen($url, "r"); if($url){ while(!feof($fp)) { $tmp = fgets($fp, 1024); $temp .= $tmp; } fclose($fp); } return $temp; } ?>
Initial URL
Initial Description
Initial Title
Get Twitter Data using twitter API
Initial Tags
data, api, twitter
Initial Language
PHP