PlayestStotly
New Member
Basically, when I'm trying to add multiple items from an RSS feed to an XML file using php, the insertBefore class adds the newest items the wrong way (ie, I want it to add them at the top of the file, from oldest to newest, but instead it adds them newest to oldest) How can I fix this? (Sorry for the terrible wording) Here's my code:\[code\]$dom = new DOMDocument;$dom->formatOutput = true;$dom->preserveWhiteSpace = false;$dom->load(myfile);$channel = $dom->getElementsByTagName('channel');foreach ($channel as $channels) {$item1 = $dom->createElement('item');$item2 = $dom->createElement('item');$item3 = $dom->createElement('item');$title1 = $dom->createElement('title', $t1);$title2 = $dom->createElement('title', $t2);$title3 = $dom->createElement('title', $t3);$content1 = $dom->createElement('media:content'); $conatt1 = $dom->createAttribute('url');$content2 = $dom->createElement('media:content'); $conatt2 = $dom->createAttribute('url');$content3 = $dom->createElement('media:content'); $conatt3 = $dom->createAttribute('url');$conatt1->value = http://stackoverflow.com/questions/15734361/$u1;$conatt2->value = $u2;$conatt3->value = $u3;$channels->insertBefore($item1, $channels->firstChild); $channels->insertBefore($item2, $channels->firstChild); $channels->insertBefore($item3, $channels->firstChild); $item1->appendChild($title1); $item2->appendChild($title2); $item3->appendChild($title3); $item1->appendChild($content1); $item2->appendChild($content2); $item3->appendChild($content3); $content1->appendChild($conatt1);$content2->appendChild($conatt2);$content3->appendChild($conatt3);}\[/code\]and the XML it makes=\[code\]<channel> <item> <title>item3</title> <media:content url="url3"/> </item> <item> <title>item2</title> <media:content url="url2"/> </item> <item> <title>item1</title> <media:content url="url"/> </item>//rest of the RSS </channel>\[/code\]But I want it so it adds the items like this:\[code\]<channel> <item> <title>item1</title> <media:content url="url1"/> </item> <item> <title>item2</title> <media:content url="url2"/> </item> <item> <title>item3</title> <media:content url="url3"/> </item>//rest of the RSS </channel>\[/code\]Any advice (again, sorry for the terrible explanation)