0

Welcome! I have a question. Today i tried to get json api from URL and i have this code:

 <?php
$url = "http://services.faa.gov/airport/status/LAX?format=json";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);
$json = curl_exec($ch);
if(!$json) {
    echo curl_error($ch);
}
curl_close($ch);
print_r(json_decode($json));
?>

In return in html i have something like this:

 stdClass Object ( [delay] => false [IATA] => LAX [state] => California [name] => Los Angeles International [weather] => stdClass Object ( [visibility] => 10 [weather] => Overcast [meta] => stdClass Object ( [credit] => NOAA's National Weather Service [updated] => 9:53 PM Local [url] => http://weather.gov/ ) [temp] => 54.0 F (12.2 C) [wind] => East at 12.7mph ) [ICAO] => KLAX [city] => Los Angeles [status] => stdClass Object ( [reason] => No known delays for this airport. [closureBegin] => [endTime] => [minDelay] => [avgDelay] => [maxDelay] => [closureEnd] => [trend] => [type] => ) )

And now my question is how to style it in css and display it nice not in this way like above

0

1 Answer 1

1

When you use:

$obj = json_decode($json);

It will return std class object, you can access its values like:

$obj->name;
$obj->delay;

and so on. Now you can use your own html & css to display it nice

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.