-2

Possible Duplicate:
A simple program to CRUD node and node values of xml file

Hi i have xml file with following attributes

<user>
 <info>
  <id>XXXXXX</id>
 </info>
</user>

I want to replace user id every time when the page loads and then save file with new id, the variable which gets id from user is $uid.

3
  • 1
    read DOMDocument ( php.net/manual/en/class.domdocument.php ) or SimpleXML ( php.net/manual/en/book.simplexml.php ) manual. Commented Feb 26, 2012 at 15:26
  • If this is all the xml within the file would it not be easier to have a template with a placeholder then you can use simple str_replace to insert the values then replace the file, else you would need to xpath the node and then rebuild the xml Commented Feb 26, 2012 at 15:33
  • Sorry! but as a beginner theses terms are bit advance for me it would be more easy if you can post the code here related to example above thanks. Commented Feb 26, 2012 at 15:45

1 Answer 1

1

Use SimpleXML

  • load the file with $xml = simplexml_load_file('filename')
  • manipulate the value in $xml
  • save the output of $xml->asXML();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.