Jump to content

Recommended Posts

Use glob

 

foreach (glob('*.xml')) as $file) {
    $fileData = file_get_contents($file);
     // parsing data here
}

Thanks for your fast reply.

Can you please explain how to include "scandir"?

 

I have this:

$dir    = 'templates';
$files = scandir($dir); 

foreach (glob("*.xml") as $filename) {
    echo "<p>$filename size " . filesize($filename) . "</p>\n";
}

..but it doesn´t output anything.

The below doesn't use scandir but it does the same thing as scandir but it also filters what is in the folder.

 

$dir = "templates";
foreach (glob($dir . "/*.xml") as $filename) {
    echo "<p>$filename size " . filesize($filename) . "</p>\n";
}

 

That should scan the templates dir for xml files.

 

For a scandir example:

$dir    = '/templates';

$files = scandir($dir);
foreach ($files as $filename) {
     if (stristr($filename, ".xml") !== false) {
         $fileData = file_get_contents($file);
         // parsing data here
     }
}

 

As you can see, glob is easier as it pulls what you want, not everything including the kitchen sink.

 

EDIT:

Modified the scandir version to be correct.

Nevermind...  I finally got it. :P

 

I changed it to this:

<?php 
$dir    = 'templates/*'; 

foreach (glob($dir . "/template.xml") as $filename) {
    echo "$filename size " . filesize($filename) . "<br />\n"; 

ini_set('zend.ze1_compatibility_mode', '0'); 
$xml = simplexml_load_file($filename); 

print("<p>
<img src=\"$xml->thumb\" alt=\" $xml->tempname \" title=\" $xml->tempname \" /><br />
Name: $xml->tempname<br />
Created by: <a href=\"mailto:$xml->email\">$xml->creator</a>
</p>"); 
} 
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.