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 683555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:43:12+00:00 2026-05-14T01:43:12+00:00

I’m building a simple application. It’s a user interface to an online order system.

  • 0

I’m building a simple application. It’s a user interface to an online order system.

Basically, the system is going to work like this:

  1. Other companies upload their purchase orders to our FTP server. These orders are simple XML files (containing things like customer data, address information, ordered products and the quantities…)

  2. I’ve built a simple user interface in HTML5, jQuery and CSS — all powered by PHP.

  3. PHP reads the content of an order (using the built-in features of SimpleXML) and displays it on the web page.

So, it’s a web app, supposed to always be running in a browser at the office. The PHP app will display the content of all orders. Every fifteen minutes or so, the app will check for new orders.

How do I loop through all XML files in a directory?

Right now, my app is able to read the content of a single XML file, and display it in a nice way on the page.

My current code looks like this:

// pick a random order that I know exists in the Order directory:
$xml_file = file_get_contents("Order/6366246.xml",FILE_TEXT);
$xml = new SimpleXMLElement($xml_file);

// start echo basic order information, like order number:
echo $xml->OrderHead->ShopPO;
// more information about the order and the customer goes here…

echo "<ul>";

// loop through each order line, and echo all quantities and products:
foreach ($xml->OrderLines->OrderLine as $orderline) {
    "<li>".$orderline->Quantity." st.</li>\n".
    "<li>".$orderline->SKU."</li>\n";
}
echo "</ul>";

// more information about delivery options, address information etc. goes here…

So, that’s my code. Pretty simple. It only needs to do one thing — print out the content of all order files on the screen — so me and my colleagues can see the order, confirm it and deliver it.

That’s it.

But right now — as you can see — I’m selecting one single order at a time, located in the Order directory. But how do I loop through the entire Order directory, and read aand display the content of each order (like above)?

I’m stuck. I don’t really know how you get all (xml) files in a directory and then do something with the files (like reading them and echo out the data, like I want to).

  • 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-14T01:43:13+00:00Added an answer on May 14, 2026 at 1:43 am

    Try the glob function:

    $files = glob("Order/*xml");
    
    if (is_array($files)) {
    
         foreach($files as $filename) {
            $xml_file = file_get_contents($filename, FILE_TEXT);
            // and proceed with your code
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.