使用tumblr API,后期图像不会显示

时间:2011-07-11 13:34:57

标签: php api tumblr

<?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>";

?>

这是我制作的剧本。我只能获取第一篇文章,但我希望显示所有帖子,并且不显示帖子图片。

2 个答案:

答案 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 . '" />';
} 

但是它只显示了几张图片而不是所有的想法?