Zorglub Posted August 23, 2021 Share Posted August 23, 2021 I have this code: <?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); //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; ?> But how do I put it into HTML though? Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/ Share on other sites More sharing options...
requinix Posted August 23, 2021 Share Posted August 23, 2021 The first step to putting it into HTML is describing what "put it into HTML" means to you. Or in other words, describe your problem in a way that someone who knows absolutely nothing about you or your application would be able to understand. Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/#findComment-1589300 Share on other sites More sharing options...
Barand Posted August 23, 2021 Share Posted August 23, 2021 Example... <?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); //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } ?> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample</title> </head> <body> <?= $response; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/#findComment-1589301 Share on other sites More sharing options...
Zorglub Posted August 23, 2021 Author Share Posted August 23, 2021 The goal is to mark up with html Take at look at the output, it is a cluster, but I want to mark up with HTML: "<td>" . name->model . "<td>" Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/#findComment-1589302 Share on other sites More sharing options...
Zorglub Posted August 23, 2021 Author Share Posted August 23, 2021 This a example without authentication: <?php $jsonurl = "https://reqres.in/api/users/2"; $json = file_get_contents($jsonurl); $jsonDecode = json_decode($json, true); echo "<b>E-mail:</b> " . $jsonDecode['data']['email']; echo $jsonDecode['data']['first_name']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/#findComment-1589303 Share on other sites More sharing options...
Zorglub Posted August 23, 2021 Author Share Posted August 23, 2021 51 minutes ago, Barand said: This example just takes the $response, and put it all in there. I need to control the individual cars so I can style them... 51 minutes ago, Barand said: <?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); //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } ?> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample</title> </head> <body> <?= $response; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/#findComment-1589304 Share on other sites More sharing options...
Barand Posted August 23, 2021 Share Posted August 23, 2021 38 minutes ago, Zorglub said: This example just takes the $response, and put it all in there. All you told us is that the cUrl returns $response. The answer is proportional to the detail in the question. Your "example without authentication" seems to provide your own answer. Quote Link to comment https://forums.phpfreaks.com/topic/313589-php-get-json-from-url-and-structure-it-in-html/#findComment-1589305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.