The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 2 of 2

Thread: Adding content to XML via PHP?

  1. #1

    Adding content to XML via PHP?

    I have a working XML document that I edit manually, which in turns updates a flash site.

    I want to create an online post/delete page. So I can just go to a specific site (not password protected) and just add/delete news stories from XML document.

    Here is my XML code:

    <?xml version='1.0' encoding='utf-8'?>
       <source id='Latest News:'>
    <story><br /><b><u><a href='' rel="nofollow" target='_blank'>June 10th</a></u></b><br />Content </story>
    <story><br /><b><u><a href='' rel="nofollow" target='_blank'>June 23rd</a></u></b><br />Content</story>

  2. #2
    Make a form with some text fields for the news you want to add, delete, bla bla bla, then submit your form to a php page with a code similar to:

    PHP Code:
    'test.xml'// your xml file
    $content "<?xml version='1.0' encoding='utf-8'?>\n";
    $content .=  "<news>\n";
    $content .=  "<source id='Latest News:'>\n";
    // Here you loop form values for the <story> node like :
    $content .= "<story>".$_POST['value1']."</story>";
    $content .= "<story>".$_POST['value2']."</story>";
    // Or do it with a foreach, or whatever you like,...
    $content .=  "</source>\n";
    $content .= "</news>\n";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

    // In our example we're opening $filename in append mode.
       // The file pointer is at the bottom of the file hence
       // that's where $somecontent will go when we fwrite() it.
    if (!$handle fopen($filename'a')) {
    "Cannot open file ($filename)";

    // Write $somecontent to our opened file.
    if (fwrite($handle$somecontent) === FALSE) {
    "Cannot write to file ($filename)";
    "Success, wrote ($somecontent) to file ($filename)";

    } else {
    "The file $filename is not writable";
    be sure to set file permissions in order to write it.

    Last edited by pixelisfun; February 25th, 2005 at 09:38 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012