I have an rss feed that is formatted something like this:
<item><posturl>mysite.com/abc.html</posturl><imagepath>123.jpg</imagepath></item><item><posturl>mysite.com/def.html</posturl><imagepath>456.jpg</imagepath> </item><item><posturl>mysite.com/ghi.html</posturl><imagepath>789.jpg</imagepath> </item>
I have a script where I want to extract both the values above. I can extract one of the values and build html code using code like:
<?php $xml = simplexml_load_file('http://myrssfeed.com'); $imgs = $xml->xpath('//imagepath'); echo '<ul>'; foreach($imgs as $output1) { echo '<li><img src="' . $output1 . '"></li>'; } echo '</ul>'; ?>
This works like a charm thanks to all the help from people here. But I need to expand that second echo line to read something like:
echo '<li><a href="' . $output2 . '"><img src="' . $output1 . '"></a></li>';
I need help on how to extract $output2 = posturl within the same item as $output1.
Basically I need to display the images as links... both imagepath and posturl are elements within item.
Many thanks.