Page 1 of 1

Changing file name based on XML content

Posted: Tue Jul 07, 2009 11:51 pm
by ananda
I have a PHP script that receives an XML file, this XML will then be sent to my webserver. However I need to change the XML file's name according to 1 content of my XML file that I received before sending it to the webserver.

Anyone knows a script that does this?

thanks a bunch

Re: Changing file name based on XML content

Posted: Wed Jul 08, 2009 12:14 am
by susrisha
rename is the function to be used

Code: Select all

 
rename();
 

Re: Changing file name based on XML content

Posted: Wed Jul 08, 2009 1:04 am
by ananda
Thanks for the reply, the rename function is used to rename a file, however I would to specifically rename the file based on one of the "XML attributes" inside the XML files I received.

example, if I receive an xml file called test.xml and inside this xml file there are attributes:

<name>test</name>
<address>test adress</address>
<phone>9000</phone>

and I want to automatically rename my xml file that i will send to the server = 9000.xml

how can I do this?

thank you

Re: Changing file name based on XML content

Posted: Wed Jul 08, 2009 1:09 am
by SvanteH

Code: Select all

<php
  $data = "<name>test</name><address>test adress</address><phone>9000</phone>";
 
  $element = "phone";
  preg_match("/<$element>(.*?)<\/$element>/", $data, $match);
  
  //Outputs 9000 
  echo $match[1];
 
?>