<?php
$feedURL = 'http://########.tumblr.com/api/read/';
$xml = simplexml_load_file($feedURL);
// $posts = $xml->xpath("/tumblr/posts/post");
foreach($xml->posts->post as $post){
$post= $xml->posts->post->{'photo-url'};
}
echo "<pre>";
print_r($post);
echo "</pre>";
?>
这是我制作的剧本。我只能获取第一篇文章,但我希望显示所有帖子,并且不显示帖子图片。
答案 0 :(得分:1)
试试这个:
foreach($xml->posts->post as $post){
$post_urls[] = (string) $post->{'photo-url'};
}
echo "<pre>";
print_r($post_urls);
echo "</pre>";
评论更新:
foreach($xml->posts->post as $post){
$posts[] = (array)$post->attributes() + (array) $post->children();
}
echo "<pre>";
print_r($posts);
echo "</pre>";
更新2:
foreach($xml->posts->post as $post){
$img = (string) $post->{'photo-url'};
echo '<img src="' . $img . '" />';
}
答案 1 :(得分:1)
我已经使用
了foreach($xml->posts->post as $post){
$img = (string) $post->{'photo-url'};
echo '<img src="' . $img . '" />';
}
但是它只显示了几张图片而不是所有的想法?