the xml file has only two entries in it. The php function works fine, reads the xml file and all the jazz. It takes the $filename, matches it to the xml attribute filename - then takes the caption from the corresponding tag and loads it into $title which is then loaded into $caption and viola it works. If it doesn't work then it returns a caption of no title (which also works btw).
My only problem right now is with the conditional statement inside the for loop. I have it set at a value of 2 because in the xml, there are two entries. However, when the page loads it loads the value of the second entry. If I change the value to 1, then it loads the first entry.
Any suggestions? Btw, I'm a flash developer learning php.
Below is my code:
$img = $filename;
include 'example.php';
xml = new SimpleXMLElement($xmlstr);
for ($i = 0; $i < 2; $i = $i + 1) {
if ((string) $xml->image[$i]->filename == $filename) {
foreach ($xml->image[$i]->title as $title) {
}
} else {
$title = 'no title';
}
}
$caption = $title;
Here is the xml:
<images>
<image>
<filename>img_01.jpg</filename>
<title type="caption">caption for image 1</title>
</image>
<image>
<filename>img_02.jpg</filename>
<title type="caption">caption for image 2</title>
</image>
</images>