TumblrをXMLで読み込む
とりあえずテキストのタイトルを読み出してみました
$contents = file_get_contents('http://osamuya.tumblr.com/api/read');
$xml = simplexml_load_string( $contents, 'SimpleXMLElement', LIBXML_NOCDATA ) or die("パースエラー");
#echo $xml['version']."
\n";
#array_reverse($xml->posts->post);
$i =0;
foreach ($xml->posts->post as $post) {
if ($i < 10) {
foreach($post->attributes() as $a => $b) {
if ($a=='url') {
$url = $b;
if ($post->{"regular-title"}) {#自分で書いたブログ
echo "- ".$post->{"regular-title"}." [Regular]
\n";
$i++;
} elseif ($post->{"quote-text"}) {
$quote_text = $post->{"quote-text"};
$quote_text = strip_tags($quote_text);
$quote_text = preg_replace('/ /','',$quote_text);
$quote_text = ltrim($quote_text);
$quote_text = mb_substr($quote_text,0,15);
echo "- ".$quote_text." [Quote]
\n";
$i++;
}
}
}
} else {
break;
}
}
/*
foreach ($xml->posts->post as $title) {
if ($title->{"regular-title"}) {
echo "- ".$title->{"regular-title"}."
\n";
}
}
*/
#var_dump($xml);
?>