I'm working with this script below to add text from an input field to an XML file. I'm confused on adding a an item to the top of list, maybe firstChild? Because when ever the PHP posts the text from the input field it adds it to the bottom of the XML tree, is there anyway to have it be the first item on the tree?
<?php
if ($_POST['post']) {
$xml = simplexml_load_file('feed.xml');
$item = $xml->channel->addChild('item');
$item->addChild('title', htmlspecialchars($_POST['post']));
file_put_contents('feed.xml', $xml->asXML());
}
?>
Here's what I want the XML to look like.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<item>
<title>Item 3</title>
</item>
<item>
<title>Item 2</title>
</item>
<item>
<title>Item 1</title>
</item>
</channel>
</rss>