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

  • Home
  • SEARCH
  • 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 560765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:22:42+00:00 2026-05-13T12:22:42+00:00

I am currently using SimpleXML to reading an xml file to generate my first

  • 0

I am currently using SimpleXML to reading an xml file to generate my first array. This array displays a list of images that are found in a directory and written to xml file.

This has worked for me in the past until I upload new photos to the same album. I like to know what one does to get a complete list of images that got uploaded to the end of that first array. Any suggestions?

XML File:

<album>
<image path="/albums/1/images/100_4124.jpg" />
<image path="/albums/1/images/100_4307.jpg" />
<image path="/albums/1/images/100_4335.jpg" />
</album>

SimpleXML to get array:

$xml = simplexml_load_file('/albums/1/photos.xml');
foreach ($xml->image as $image)  {
    echo '<li><img src="'.$image.'"></li>';
}

What I am getting for my results:

<li><img src="/albums/1/images/100_4124.jpg"></li>
<li><img src="/albums/1/images/100_4307.jpg"></li>
<li><img src="/albums/1/images/100_4335.jpg"></li>

Scanning the directory for all images:

if ($handle = @opendir('/albums/1/')) {
    $filenames = array();
    while (false !== ($file = readdir($handle))) {
        $ext = substr($file, strrpos($file, '.') + 1);
        if ($file != '.' && $file != '..') {
            $filenames[] = $file;
            $total++;
        }
    }
}
closedir($handle);

foreach ($filenames as $filename) {
    echo '<li><img src="'.$filename.'"></li>';
}

What I would like to get for results using both arrays:

<li><img src="/albums/1/images/100_4124.jpg"></li>
<li><img src="/albums/1/images/100_4307.jpg"></li>
<li><img src="/albums/1/images/100_4335.jpg"></li>    

<li><img src="/albums/1/images/100_9000.jpg"></li>
<li><img src="/albums/1/images/100_9001.jpg"></li>
<li><img src="/albums/1/images/100_9002.jpg"></li>

The last 3 images that are missing from xml file would be added it to the end of the list.

  • 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-05-13T12:22:43+00:00Added an answer on May 13, 2026 at 12:22 pm

    Perhaps this would work for you?

    <?php
    
    $images = array();
    
    foreach ($xml->image as $image) {
        $images[] = $image;
    }
    
    foreach (array_diff($filenames, $images) as $image) {
        $images[] = $image;
    }
    
    foreach ($images as $image) {
        echo '<li><img src="' . $image . '" /></li>';
    }
    
    ?>
    

    This is assuming that $image from the $xml->image and $filename from your dir search are formatted the same. From what you’ve shown they are. If they aren’t should be easy enough to run them through a quick regex to get them in a state where they are comparable.

    Any who it looks like array_diff() is what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It indeed won't do that for you. It will at… May 16, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer You shouldn't be using regex to parse HTML. Walk the… May 16, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer string[] cars = new string[]{"Volvo", "SAAB"}; foreach (var car in… May 16, 2026 at 4:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am Parsing XML currently using: $data = simplexml_load_string($xmlFile); foreach($data->item as $key => $current){
Currently I'm using PHP to load multiple XML files from around the web (non-local)
I am currently using Watir with Firefox and it seems that when I try
I'm currently using JCarousel to highlight featured posts in Wordpress. The carousel displays above
I'm currently using the JNI to generate C headers for native methods being used
I am currently using this code to bring up an info window -(IBAction)showInfo:(id)sender {
I am scraping a list of RSS feeds by using cURL, and then I
I am currently using: $page = simplexml_load_file('http://www.example.com/page.html'); In my code I would like to
Currently i'm using the following, which seems quite slow for multiple clips: static function
I have a function which uses simplexml to return the first level of nodes

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.