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
Changing file name based on XML content
Moderator: General Moderators
Re: Changing file name based on XML content
rename is the function to be used
Code: Select all
rename();
Re: Changing file name based on XML content
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
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
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];
?>