fopen - I need to find a way to edit XML files when a user submits a form using PHP -


so have web page displays data of xml file. have form should ideally able change data. figured best way accomplish use fopen function in php , edit specific line of text. string won't long, 4 words max. how use fopen , series of functions open, read , write files find line of code , replace it?

i think should following:

  1. match name of input tags in html nodes in xml (this suggestion have code more organized)

  2. when post data server, in php code, using simplexml can following

giving following xml file

<root>     <config id="1">         <name>old name</name>         <category>old category</category>     </config>     <config id="2">         <name>old name</name>         <category>old category</category>     </config> </root> 

//load xml file $xml = simplexml_load_file('path xml file'); //update values want update foreach($xml->root->config $configgroup) {     //set $idtoupdate variable id of group want update.     if ($configgroup['id'] == $idtoupdate)     {         $configgroup->name = $_post['name' . $idtoupdate];//your html must have proper input names.         break;     } }  //save changes $xml->asxml('path xml file'); 

hope helps


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -