arok
arok

Reputation: 1845

how to load more than one xml file using php

If I have more than one XML file with different name how to read all the XML file, for example i have three XML file inside the folder(/data/data/www/)filenames(Message.xml,example.xml,data.xml) but now i am only reading one file,how can I call the other files? below is my code.thanks

PHP

<html>
<body>

<?php
$xml=simplexml_load_file("/data/data/www/Message.xml");
print_r($xml);

echo $xml->TEMPLATE . "<br>";
echo $xml->RECIPIENT_NUM."<br>";
?>  

</body>
</html>

Upvotes: 0

Views: 284

Answers (3)

Xavi
Xavi

Reputation: 2594

$dir = "/data/data/www/";
if (is_dir($dir)) {
  if ($dh = opendir($dir)) {
    while (($file = readdir($dh)) !== false) {
      if (($file !== '.') && ($file !== '..') ) {
    $xml = simplexml_load_file($dir . $file);  
      $message= $xml->TEMPLATE . "<br>";
      $mobile=$xml->MESSAGES->MESSAGE->RECIPIENT_NUM."<br>";

    }
  }

  closedir($dh);
  }
}

Upvotes: 1

LFS96
LFS96

Reputation: 876

<html>
<body>

<?php
$xml0=simplexml_load_file("/data/data/www/Message.xml");
$xml1=simplexml_load_file("/data/data/www/data.xml");
print_r($xml0);
print_r($xml1);

echo $xml0->TEMPLATE . "<br>";
echo $xml0->RECIPIENT_NUM."<br>";
echo $xml1->TEMPLATE . "<br>";
echo $xml1->RECIPIENT_NUM."<br>";
?> 


<?php
$xml=  readdir ([ resource $dir_handle ]
while($xml)
$i= strstr ($xml= readdir ([ resource $dir_handle ] ) , "XML")
if ($i != 0)
{
 $xml0=simplexml_load_file("/data/data/www/$xml");
}
}
?>

Like this i think

Upvotes: 0

randomizer
randomizer

Reputation: 1649

Assuming the filenames are in an array, you can do something like:

foreach ($files as $file) {
    $xml=simplexml_load_file($file);
    print_r($xml);    
    echo $xml->TEMPLATE . "<br>";
    echo $xml->RECIPIENT_NUM."<br>";
}

Upvotes: 0

Related Questions