1

I have found several questions and answers pertaining to my question, but I'm getting a little confused. Perhaps clarification from someone would help.

Sadly, I am working in PHP 4 - no chance of upgrading. :( (See comments below... I'm stuck working on a client server who doesn't want to upgrade from a folksy/non-PHP-updating web host.)

My aim is to make a web-based GUI that updates the contents of an XML Flash gallery file. So basically the XML file is nothing more than this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
    <pic>
        <image>images/image1.jpg</image>
    </pic>
    <pic>
        <image>images/image2.jpg</image>
    </pic>
     <pic>
        <image>images/image3.jpg</image>
    </pic>
</images>

The backend, I'm hoping, is simply going to look like text boxes with the URLs for the images and an "update" button. They'll also be able to add another image by clicking "add image".

Now, I found this question: Read and write an XML file with PHP which seemed to answer what I was looking for. My only concern is, let's say we want to edit the URL of the second image, and there are 8 images? Not to mention, how to populate the text boxes?

The only idea I had was to create a function that basically writes something like:

<pic>
    <image>$_POST['textbox1']</image>
</pic>

and it just loops through each textbox, writes that, then writes a new XML file each time there is any update?

Perhaps I'm making this more complicated than it should be.

Community
  • 1
  • 1
Sara
  • 133
  • 5
  • 11
  • 4
    PHP 4 is dead and no longer supported. If at all possible, one should really, really not be writing new software for it any more. This stuff is also much simpler using PHP 5's native libraries. Are you 1000% sure you can't switch? – Pekka Jun 03 '11 at 08:00
  • I totally agree with this, but I'm not in control of the PHP environment. I tried to push to get my client to switch to a host that upgraded and they didn't want to do it. I am a mite frustrated because I see that it would be a breeze with PHP5! Oh well. – Sara Jun 03 '11 at 08:02
  • 5
    hope you charge double for the extra effort and pain? :) – Gordon Jun 03 '11 at 08:04

1 Answers1

0

Why not simply define the textboxes as the following?

<input type="text" name="picture[]"/>

Then in PHP you just access all values using

foreach ($_POST['picture'] as $pictureUrl)
{
    $buffer.= '<pic><image>'.$pictureUrl.'</image></pic>';
}

You definitely want to check whether the array is set or not, etc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ben
  • 355
  • 2
  • 12
  • This would be great! Almost perfect :). Do you have any ideas on how to get the values in the tags into the textboxes so they're "sticky"? – Sara Jun 03 '11 at 08:10
  • As a quick'n'dirty way you could use preg_match_all and then just run this regex over it (.*) – Ben Jun 03 '11 at 08:18
  • Hmm, okay. I've never used preg_match_all before but I can look into it. From what I'm seeing it looks like it would be very useful. Many thanks! – Sara Jun 03 '11 at 08:27