I have a serialized string comming in with POST:
$imgdata = $_POST['imgdata']; // li[]=2&li[]=3&li[]=1&li[]=4
In this example 001 is reordered after 003 How can I update my XML file with this new order? I think I need simpleXML or xpath. Here are my thoughts:
// 1. load xml string
$xml = simplexml_load_file('test.xml');
/*
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album>
<img src="001.jpg" caption="First caption" />
<img src="002.jpg" caption="Second caption" />
<img src="003.jpg" caption="3th caption" />
<img src="004.jpg" caption="4th caption" />
</album>
</gallery>
*/
// 2. sort nodes
// $new_xml_string = "......";
// 3. write out new XML file
$handle = fopen("images.xml", 'w');
fwrite($handle, $new_xml_string);
fclose($handle);