Reputation: 105
I am reading an xml file with:
<imageref>image1.jpg|image2.jpg|image3.jpg|image4.jpg</imageref>
<hotelname>villa test</hotelname>
foreach ($filtered as $hotel) {
$xmlhotels[] = array(
'image'=>(string)$hotel->imageref,
'villaname'=>(string)$hotel->hotelname
);
}
When I echo the villaname foreach value I get it.
foreach ($myhotels as $villa) {
echo"",$villa['villaname'],""; }
How can I echo just the first image (image1.jpg) from the xml file.
Upvotes: 0
Views: 77
Reputation: 1370
Use the explode() and do something like this:
foreach ($filtered as $hotel) {
$xmlhotels[] = array(
'image'=>explode('|', $hotel->imageref),
'villaname'=>(string)$hotel->hotelname
);
}
foreach ($myhotels as $villa) {
echo $villa['villaname'];
echo $villa['image'][0];
}
Upvotes: 2