Jump to content

PHP: How to read/ parse JSON so I can style the text in HTML


Zorglub
 Share

Go to solution Solved by requinix,

Recommended Posts

My try so far...:

I want to get the data, then set all the cars up in a list (<li></li>) so I can style it later.

<?php
//The URL of the resource that is protected by Basic HTTP Authentication.
$url = 'https://gw.bilinfo.net/listingapi/api/export';

//Your username.
$username = 'demo';
//Your password.
$password = 'ocfB6XzF73';

//Initiate cURL.
$ch = curl_init($url);
 
//Specify the username and password using the CURLOPT_USERPWD option.
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);  

//Tell cURL to return the output as a string instead
//of dumping it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Execute the cURL request.
$response = curl_exec($ch);
$jsonDecode = json_decode($url, true);
echo "<b>Bil:</b> " . $jsonDecode['Vehicles']['Pictures'];

//Check for errors.
if(curl_errno($ch)){
    //If an error occured, throw an Exception.
    throw new Exception(curl_error($ch));
}

//Print out the response.
echo $response;
?>

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.