Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello How To Generate HTML Table from Curl Response ?


my code

PHP
<pre><?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.travelpayouts.com/v1/prices/cheap?origin=SAW&destination=AYT&depart_date=2022-10-26&return_date=2022-10-27¤cy=usd",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: xxxxxxxxxxxxxxxxxxxxx"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
    $json = json_decode($response, true);
  print_r($json);
}

?>



<?php
for($i=0;$i<count($data[0]["data"]);$i++) {
  echo('<tr>');
  echo('<td>' . $data[0]['data'][$i]['price'] . '</td>');
  echo('<td>' . $data[0]['data'][$i]['airline'] . '</td>');
  echo('<td>' . $data[0]['data'][$i]['flight_number'] . '</td>');
  echo('</tr>');
}?>



<pre>
Array
(
    [AYT] => Array
        (
            [0] => Array
                (
                    [price] => 145
                    [airline] => PC
                    [flight_number] => 4000
                    [departure_at] => 2022-10-26T18:10:00+03:00
                    [return_at] => 2022-10-27T05:55:00+03:00
                    [expires_at] => 2022-10-26T01:55:58Z
                )

            [1] => Array
                (
                    [price] => 389
                    [airline] => PC
                    [flight_number] => 1910
                    [departure_at] => 2022-10-26T06:20:00+03:00
                    [return_at] => 2022-10-27T05:55:00+03:00
                    [expires_at] => 2022-10-26T01:55:58Z
                )

            [2] => Array
                (
                    [price] => 349
                    [airline] => PC
                    [flight_number] => 2666
                    [departure_at] => 2022-10-26T11:40:00+03:00
                    [return_at] => 2022-10-27T05:55:00+03:00
                    [expires_at] => 2022-10-26T01:55:58Z
                )

        )

)


What I have tried:

I want to export curl output to html table, but I'm getting an error. Can you help me?
Posted
Comments
Sandeep Mewara 26-Oct-22 1:17am    
Along with what you have shared, Informations like: How did you try to export and what's the error you get would really help others to provide some guidance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900