开发者

Using tumblr API, post image is not showing up

开发者 https://www.devze.com 2023-03-19 14:38 出处:网络
<?php $feedURL = \'http://########.tumblr.com/api/read/\'; $xml = simplexml_load_file($feedURL); // $posts = $xml->xpath(\"/tumblr/posts/post\");
<?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 "<开发者_C百科/pre>";

?>

This is the script that I have made. I am able to fetch only the first post, but I want all posts to be displayed and the post image is not showing up.


I've got it working using

foreach($xml->posts->post as $post){
    $img = (string) $post->{'photo-url'};
    echo '<img src="' . $img . '" />';
} 

But its only showing a couple image not all of them any ideas ?


Try this:

foreach($xml->posts->post as $post){
    $post_urls[] = (string) $post->{'photo-url'};
} 

echo "<pre>";
print_r($post_urls);
echo "</pre>";

Update for comment:

foreach($xml->posts->post as $post){
   $posts[] = (array)$post->attributes() + (array) $post->children();
} 

echo "<pre>";
print_r($posts);
echo "</pre>";

Update 2:

foreach($xml->posts->post as $post){
    $img = (string) $post->{'photo-url'};
    echo '<img src="' . $img . '" />';
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号