Search code examples
phparraysjsonapitumblr

Tumblr API PHP Array response into usable code in HTML and PHP


Array ( 
    [meta] => Array ( 
    [status] => 200 [msg] => OK ) 
    [response] => Array ( 
        [user] => Array ( 
            [name] => paulkin360 
            [likes] => 0 
            [following] => 2 
            [default_post_format] => html 
            [blogs] => Array ( 
                [0] => Array ( 
                    [name] => paulkin360 
                    [url] => http://paulkin360.tumblr.com/ [
                    [followers] => 0 
                    [primary] => 1 
                    [title] => Untitled 
                    [description] => 
                    [admin] => 1 
                    [updated] => 1379175176 
                    [posts] => 2 
                    [messages] => 0 
                    [queue] => 0 
                    [drafts] => 0 
                    [share_likes] => 1 
                    [ask] => 
                    [tweet] => auto 
                    [facebook] => auto 
                    [facebook_opengraph_enabled] => Y [type] => public 
                ) 
            ) 
        ) 
    ) 
)

So far that is what I have but I would want to reorganise this in html


Solution

  • This is an example of usage to get you started, you'll need to build the actual HTML yourself.

    <?php
    $user = $your_array['response']['user'];
    ?>
    
    <div>Name: <?php echo $user['name']; ?></div>
    <div>Likes: <?php echo $user['likes']; ?></div>
    <div>Following: <?php echo $user['following']; ?></div>
    
    <?php foreach($user['blogs'] as $blog): ?>
    <div class="blog">
        <div>Name: <?php echo $blog['name']; ?></div>
        <div>URL: <?php echo $blog['url']; ?></div>
        <div>Followers: <?php echo $blog['followers']; ?></div>
        <div>Title: <?php echo $blog['title']; ?></div>
    </div>
    <?php endforeach; ?>