title: PHP: How do I loop through every XML file in a directory?
body: <p>I'm building a simple application. It's a user interface to an online order system.</p>
  <p>Basically, the system is going to work like this:</p>
  <ol>
  <li><p>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…)</p>
  </li>
  <li><p>I've built a simple user interface in HTML5, jQuery and CSS — all powered by PHP.</p>
  </li>
  <li><p>PHP reads the content of an order (using the built-in features of SimpleXML) and displays it on the web page.</p>
  </li>
  </ol>
  <p>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.</p>
  <h3>How do I loop through all XML files in a directory?</h3>
  <p>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.</p>
  <p><strong>My current code looks like this:</strong></p>
  <pre><code>// pick a random order that I know exists in the Order directory:
  $xml_file = file_get_contents(&quot;Order/6366246.xml&quot;,FILE_TEXT);
  $xml = new SimpleXMLElement($xml_file);
  
  // start echo basic order information, like order number:
  echo $xml-&gt;OrderHead-&gt;ShopPO;
  // more information about the order and the customer goes here…
  
  echo &quot;&lt;ul&gt;&quot;;
  
  // loop through each order line, and echo all quantities and products:
  foreach ($xml-&gt;OrderLines-&gt;OrderLine as $orderline) {
      &quot;&lt;li&gt;&quot;.$orderline-&gt;Quantity.&quot; st.&lt;/li&gt;\n&quot;.
      &quot;&lt;li&gt;&quot;.$orderline-&gt;SKU.&quot;&lt;/li&gt;\n&quot;;
  }
  echo &quot;&lt;/ul&gt;&quot;;
  
  // more information about delivery options, address information etc. goes here…
  </code></pre>
  <p>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.</p>
  <p>That's it.</p>
  <p>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)?</p>
  <p>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).</p>