开发者

How to Loop through XML subnodes using PHP's simplexml

开发者 https://www.devze.com 2023-01-24 18:33 出处:网络
OK, I\'m having trouble looping through these sub-nodes.For this example, I\'ll show you the code I am using to try to grab the Amenities from a Hotel Info feed.The XML doesn\'t appear to be formatted

OK, I'm having trouble looping through these sub-nodes. For this example, I'll show you the code I am using to try to grab the Amenities from a Hotel Info feed. The XML doesn't appear to be formatted great, a开发者_如何学编程nd unfortunately I don't have control over that. Here's my code.

$xml = simplexml_load_file("http://www.2-20.com/hotelRoomSearchDetails.cfm?pnum_hotel_seq_id=210&pchr_room_type=STUDIO%22")
$hotel_amenities = $xml->contentDataResults->hotelContent->hotelAmenities;

foreach($hotel_amenities as $a){
    echo $a->amenity;
}

It is only returning the first amenity however.


$hotel_amenities = $xml->contentDataResults->hotelContent->hotelAmenities->children();
foreach($hotel_amenities as $a)
{
  echo $a;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消