flickrのフィードをパースしてTwitterに投稿
<?php $rss = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?id=22896965@N04&lang=en-us&format=atom'); foreach($rss->entry as $entry) { $tag = ""; $str = trim(substr(strstr(strip_tags($entry->content),":"),1)); foreach($entry->link[0]->attributes() as $key => $val) { if($key == "href"){ $url = $val; } } foreach ($entry->category as $category){ foreach($category->attributes() as $key => $val) { if($key == "term"){ $tag = $tag . "[$val]"; } } } $ary[trim($entry->updated)] = $str ." " .$url . " " .$tag; } $ary = array_reverse($ary); $id = 0; $file_name = "time.txt"; $handle = @fopen($file_name, "r"); if ($handle) { if (!feof($handle)) { $time = fgets($handle, 4096); } fclose($handle); } foreach ($ary as $key => $val){ if($key > $time){ $url = "http://twitter.com/statuses/update.xml?"; $username = "R_K"; $password = "************"; $params = "status=". rawurlencode($val); $result = file_get_contents($url.$params , false, stream_context_create(array( "http" => array( "method" => "POST", "header" => "Authorization: Basic ". base64_encode($username. ":". $password) ) ))); $time = $key; } } $fp = fopen( $file_name, "w" ); fputs($fp, $time); fclose( $fp ); ?>
参考
http://blog.myrss.jp/archives/2006/11/phprss.html
http://phpspot.org/blog/archives/2006/11/phprss.html
http://d.hatena.ne.jp/hirataka522/20080126/1201300282