PHP XML and Graphics Help please

Hi, sorry I’m a bit newbie to PHP and I’ve been looking around but having trouble finding out how to do this.
I’m making a simple PHP website but I have no idea how to get PHP to read data form an xml. I’ve heard of simpleXML but I need a bit of help, epic newb here XD

Anyway, here is the XML I want PHP to take the data form.

<Object1 color="Red" weight="5" image="images/Object1.png"/> <Object2 color="Green" weight="4" image="images/Object2.png">

I have an array in my php that randomly selects one of the objects.
I want to put the values in an array and then store them as separate variables.
The file then prints:
[php]print “The object you see is $color and weighs $weight kilos.”;[/php]

Any help much appreciated :slight_smile:

have you opened and read the xml file ?
maybe look in to how to open and read a txt file first.

but then you could but this is very ruff wont work but will give you an idiea how to get the part you need regx is probably better but I am not good at it.

[php]$colour = explode(‘color="’, $colour ); /// needs more as it will leave you with to much html code but you will see what its doing as a quick guide
$colour = str_replace(’"’,’’, $colour);
echo $colour;[/php]
and that’s it you would need to make a loop for the

Sponsor our Newsletter | Privacy Policy | Terms of Service