0

我正在尝试将 while 循环的结果添加到 xml 请求中。但它没有正确显示。下面我首先创建一个函数,然后我尝试使该函数在 xml 请求 curl 标记内工作。很难解释,也更容易看到:

 //Getting room groups
    function roomGroups(){
    $i = 2;
            while(isset($_GET['ad'.$i]))
            {
                $adult = $_GET['ad'.$i];
                $child = $_GET['ch'.$i];
                $childAge = $_GET['ch'.$i];
                echo "<RoomGroup><Room><numberOfAdults>".$adult."</numberOfAdults><numberOfChildren>".$child."<childAges>".$childAge."</childAges></Room></RoomGroup>"; 
                $i++; 
                }}                  
    //Room availablility Request
    $ch1 = curl_init(); 
    $fp1 = fopen('room_request.xml','w'); 
    curl_setopt($ch1, CURLOPT_URL, "http://api.ean.com/ean-services/rs/hotel/v3/avail?cid=379849&minorRev=13&apiKey=4sr8d8bsn75tpcuja6ypx5g3&locale=en_US&currencyCode=USD&customerIpAddress=67.20.125.193&customerUserAgent=Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/535.11+(KHTML,+like+Gecko)+Chrome/17.0.963.79+Safari/535.11&customerSessionId=0ABAA856-8502-E913-6982-E2210F904B72&xml=<HotelRoomAvailabilityRequest><hotelId>".$hid."</hotelId><arrivalDate>".$arrivalDate."</arrivalDate><departureDate>".$departingDate."</departureDate><RoomGroup><Room><numberOfAdults>".$adults."</numberOfAdults><numberOfChildren>".$children."</numberOfChildren><childAges>".$ages."</childAges></Room></RoomGroup>".roomGroups()."<includeDetails>true</includeDetails></HotelRoomAvailabilityRequest>");  
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
    curl_setopt($ch1, CURLOPT_HEADER, 0); 
    curl_setopt($ch1, CURLOPT_FILE, $fp1); 
    $val1 = curl_exec($ch1); 
    curl_close($ch1);//Close curl session 
    fclose($fp1); //Close file overwrite 
    $avail = simplexml_load_file('room_request.xml');

//The url that is passing the data looks like this: /hotel_request.php?hid=370111&d=05/02/2012&a=04/30/2012&r=3&ad2=2&ch2=22=16,17,&ad3=3&ch3=33=7,13,16,&

我什么也得不到。对此的任何帮助将不胜感激!

4

1 回答 1

1

roomGroups()没有return什么,它只是echo在屏幕上。

尝试这样的事情:

function roomGroups(){
    $i = 2;
    $ret = '';
    while(isset($_GET['ad'.$i])){
        $adult = $_GET['ad'.$i];
        $child = $_GET['ch'.$i];
        $childAge = $_GET['ch'.$i];
        $ret .= "<RoomGroup><Room><numberOfAdults>".$adult."</numberOfAdults><numberOfChildren>".$child."<childAges>".$childAge."</childAges></Room></RoomGroup>"; 
        $i++; 
    }
    return $ret;
}
于 2012-04-20T19:59:35.873 回答