2013-02-23 88 views
0

我在API調用和學習階段頗爲新穎。我正在使用PHP使用Expedia開發API。我正在成功獲取響應轉儲,並且可以在頁面上顯示轉儲。然而,有人可以告訴我,我需要做什麼轉換/解析API響應並轉換爲網頁。 我真的很努力去理解我如何使用那個輸出轉換成html來顯示爲正常的假期預訂或酒店網站。爲了更好地理解我正在粘貼我從Expedia收到的回覆。請指教將Expedia API響應轉換爲html PHP

[HotelSummary] => SimpleXMLElement Object 
      (
       [@attributes] => Array 
        (
         [order] => 0 
        ) 

       [hotelId] => 425669 
       [name] => Hôtel Luxor 
       [address1] => 24, Rue Ernest Renan 
       [city] => Issy-les-Moulineaux 
       [postalCode] => 92130 
       [countryCode] => FR 
       [airportCode] => SimpleXMLElement Object 
        (
         [0] =>  
        ) 

       [supplierType] => E 
       [propertyCategory] => 1 
       [hotelRating] => 1.0 
       [confidenceRating] => 52 
       [amenityMask] => 0 
       [tripAdvisorRating] => 1.5 
       [locationDescription] => Near Paris Expo Porte de Versailles 
       [shortDescription] => <p><b>Location. </b> <br />Hôtel Luxor is located in Issy-les-Moulineaux's Gare Montparnasse - Porte de Versailles neighborhood, close to Paris Expo Porte de Versailles, Eiffel Tower, and Stade de 
       [highRate] => 43.76 
       [lowRate] => 43.76 
       [rateCurrencyCode] => EUR 
       [latitude] => 48.82882 
       [longitude] => 2.28239 
       [proximityDistance] => 1.7304468 
       [proximityUnit] => MI 
       [hotelInDestination] => true 
       [thumbNailUrl] => /hotels/6000000/5670000/5669900/5669864/5669864_4_t.jpg 
       [deepLink] => http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=425669&mode=2&numberOfRooms=1&room-0-adult-total=1&room-0-child-total=0&arrivalMonth=8&arrivalDay=17&departureMonth=8&departureDay=18&showInfo=true&locale=en_US&currencyCode=EUR 
       [RoomRateDetailsList] => SimpleXMLElement Object 
        (
         [RoomRateDetails] => SimpleXMLElement Object 
          (
           [roomTypeCode] => 200245723 
           [rateCode] => 201427808 
           [maxRoomOccupancy] => 2 
           [quotedRoomOccupancy] => 1 
           [minGuestAge] => 0 
           [roomDescription] => Moderate - shared bathroom 
           [currentAllotment] => 10 
           [propertyAvailable] => true 
           [propertyRestricted] => false 
           [expediaPropertyId] => 5669864 
           [rateKey] => 3f0bfd6a-d45b-496d-a986-eb8aade2b3e8 
           [RateInfo] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [rateChange] => false 
               [promo] => false 
               [priceBreakdown] => true 
              ) 

             [ChargeableRateInfo] => SimpleXMLElement Object 
              (
               [@attributes] => Array 
                (
                 [total] => 47.0 
                 [surchargeTotal] => 3.24 
                 [nightlyRateTotal] => 43.76 
                 [maxNightlyRate] => 43.76 
                 [currencyCode] => EUR 
                 [commissionableUsdTotal] => 57.72 
                 [averageRate] => 43.76 
                 [averageBaseRate] => 43.76 
                ) 

               [NightlyRatesPerRoom] => SimpleXMLElement Object 
                (
                 [@attributes] => Array 
                  (
                   [size] => 1 
                  ) 

                 [NightlyRate] => SimpleXMLElement Object 
                  (
                   [@attributes] => Array 
                    (
                     [promo] => false 
                     [rate] => 43.76 
                     [baseRate] => 43.76 
                    ) 

                  ) 

                ) 

               [Surcharges] => SimpleXMLElement Object 
                (
                 [@attributes] => Array 
                  (
                   [size] => 1 
                  ) 

                 [Surcharge] => SimpleXMLElement Object 
                  (
                   [@attributes] => Array 
                    (
                     [amount] => 3.24 
                     [type] => TaxAndServiceFee 
                    ) 

                  ) 

                ) 

              ) 

            ) 

           [ValueAdds] => SimpleXMLElement Object 
            (
             [@attributes] => Array 
              (
               [size] => 1 
              ) 

             [ValueAdd] => SimpleXMLElement Object 
              (
               [@attributes] => Array 
                (
                 [id] => 2048 
                ) 

               [description] => Free Wireless Internet 
              ) 

            ) 

          ) 

        ) 

      ) 

    ) 

) 

回答

0

你有一個變量的響應,那麼請爲每個這樣

例如這裏的變量是$obj裝置然後把它作爲

的foreach($ OBJ [」 HotelListResponse'] ['HotelList'] ['HotelSummary']爲 $ HOTEL){「你的html代碼在這裏爲e g:如果我需要酒店的名字}這樣的

並關閉每個末

<?php }?> 

希望這有助於