# Add and edit XML with PHP

**URL:** <https://forum.kirupa.com/t/add-and-edit-xml-with-php/284288>\
**Category:** programming\
**Created:** [March 17, 2009, 4:32pm UTC](https://forum.kirupa.com/t/add-and-edit-xml-with-php/284288 "2009-03-17T16:32:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marjoth](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Marjoth](https://forum.kirupa.com/u/Marjoth)\
**Post date:** [March 17, 2009, 4:32pm UTC](https://forum.kirupa.com/t/add-and-edit-xml-with-php/284288/1 "2009-03-17T16:32:51Z")

</div>

Hi there!

Im currently working on a script which allows me to enter new posts in a XML-file.

The XML (“config.xml”) is read by a flash application to show videos. The XML-template is as follow, and is entered for each new movie I want to publish:

```auto

      <item>
         <title>$title</title> // from form ($_POST)
         <description><![CDATA[$description]]></description> // short description of movie
         <url>$URL</url> // URL to the moviefile (FLV)
         <thumb>$thumb_url</thumb> // URL to thumbnail
      </item> 

```

I’ve created a short PHP-script which allows me to enter this details through a form. On the top and the bottom of the file there’s a tag \<movie\> and \</movie\>, and using the fgets()-function with a “while”, the script is searching for the first \<movie\>-line and place the new entery right below it.

The source code can be found here: [http://norskwebforum.no/pastebin/10961](http://norskwebforum.no/pastebin/10961) (text in norwegian, but I think you’ll understand the point).

Now, I really want to add the functionality to edit and delete posts, but I don’t know how to do this. Maybe I can generate the XML with a database, but I started with PHP two weeks ago, so I’m still pretty n00b at this. I’ve read about SimpleXML in PHP5 as a easier way of doing this, but at this point this is a little too complicated to understand…

Summary: The point is to add, edit and delete items from the XML-file within a graphical interface.

So any help would’ve been much appriciated! (I’ve done a search and found some good examples, but couldn’t transfer them into my example :/)
