Changing file name based on XML content

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ananda
Forum Newbie
Posts: 6
Joined: Mon Jun 22, 2009 9:00 pm

Changing file name based on XML content

Post 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
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Changing file name based on XML content

Post by susrisha »

rename is the function to be used

Code: Select all

 
rename();
 
ananda
Forum Newbie
Posts: 6
Joined: Mon Jun 22, 2009 9:00 pm

Re: Changing file name based on XML content

Post 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
SvanteH
Forum Commoner
Posts: 50
Joined: Wed Jul 08, 2009 12:25 am

Re: Changing file name based on XML content

Post 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];
 
?>
Post Reply