Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:11:14+00:00 2026-06-05T05:11:14+00:00

My goal is to embed Tumblr posts into a website using their provided XML.

  • 0

My goal is to embed Tumblr posts into a website using their provided XML. The problem is that Tumblr saves 6 different sizes of each image you post. My code below will get the first image, but it happens to be too large. How can I select one of the smaller-sized photos out of the XML if all the photos have the same tag of <photo-url>?

→ This is the XML from my Tumblr that I’m using: Tumblr XML.

→ This is my PHP code so far:

<?php
$request_url = "http://kthornbloom.tumblr.com/api/read?type=photo";
$xml = simplexml_load_file($request_url);
$title = $xml->posts->post->{'photo-caption'};
$photo = $xml->posts->post->{'photo-url'};
echo '<h1>'.$title.'</h1>';
echo '<img src="'.$photo.'"/>"'; 
echo "…";
echo "</br><a target=frame2 href='".$link."'>Read More</a>"; 
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:11:15+00:00Added an answer on June 5, 2026 at 5:11 am

    The function getPhoto takes an array of $photos and a $desiredWidth. It returns the photo whose max-width is (1) closest to and (2) less than or equal to $desiredWidth. You can adapt the function to fit your needs. The important things to note are:

    • $xml->posts->post->{'photo-url'} is an array.
    • $photo['max-width'] accesses the max-width attribute on the <photo> tag.

    I used echo '<pre>'; print_r($xml->posts->post); echo '</pre>'; to find out $xml->posts->post->{'photo-url'} was an array.

    I found the syntax for accessing attributes (e.g., $photo['max-width']) at the documentation for SimpleXMLElement.

    function getPhoto($photos, $desiredWidth) {
        $currentPhoto = NULL;
        $currentDelta = PHP_INT_MAX;
        foreach ($photos as $photo) {
            $delta = abs($desiredWidth - $photo['max-width']);
            if ($photo['max-width'] <= $desiredWidth && $delta < $currentDelta) {
                $currentPhoto = $photo;
                $currentDelta = $delta;
            }
        }
        return $currentPhoto;
    }
    
    $request_url = "http://kthornbloom.tumblr.com/api/read?type=photo";
    $xml = simplexml_load_file($request_url);
    
    foreach ($xml->posts->post as $post) {
        echo '<h1>'.$post->{'photo-caption'}.'</h1>';
        echo '<img src="'.getPhoto($post->{'photo-url'}, 450).'"/>"'; 
        echo "...";
        echo "</br><a target=frame2 href='".$post['url']."'>Read More</a>"; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHP from the command line and I'm trying to embed data into
Goal: I want to implement a hard-coded lookup table for data that doesn't change
Goal Replace one div with another after 5 seconds delay using jQuery. Description I
Goal: Build an Android app that discovers the names and addresses of BT devices
Goal: to programmatically determine the sizes (in bytes) of the fields of a class.
Goal : Update an existing host header for an IIS7.5 site with powershell Problem
My problem is this : Using MonoDevelop (which is the preferred environment for a
I'm writing a small sample app using Ember.js. My goal is to determine use
Goal : My intention to design a utility that could access any numeric values(
Goal: take results from recognizer stating a name in contacts, then dial their #.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.