Jump to content

jcrimmel

New Members
  • Posts

    3
  • Joined

  • Last visited

jcrimmel's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks. I'll try to figure it out.
  2. Thank you Barnad. While I've been using Joomla and editing very basic PHP for many years, I'm just recently starting to dive deeper into the coding side of it. I'm really just learning, so please excuse my ignorance. I assume your supplied code would be placed directly after the $results.... so, something like this? <?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://coingecko.p.rapidapi.com/simple/price?ids=everearn&vs_currencies=usd&include_market_cap=true&include_24hr_change=true&include_24hr_vol=true", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "X-RapidAPI-Host: coingecko.p.rapidapi.com", "X-RapidAPI-Key: 3a8cf65…………………………..4b481b" ], ]); $response = curl_exec($curl); Array ( [everearn] => Array ( [usd] => 1.868E-5 [usd_market_cap] => 0 [usd_24h_vol] => 839.09151161664 [usd_24h_change] => 1.5959917379693 ) ) $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
  3. I’m sure this is pretty easy for most of you, but I am no expert at writing code at all, and I need some help editing this code. I have a PHP API call shown below. The API call is returning data, but it is not formatted correctly. Thanks in advance. <?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://coingecko.p.rapidapi.com/simple/price?ids=everearn&vs_currencies=usd&include_market_cap=true&include_24hr_change=true&include_24hr_vol=true", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "X-RapidAPI-Host: coingecko.p.rapidapi.com", "X-RapidAPI-Key: 3a8cf65…………………………..4b481b" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } The results of the API call show up formatted as such: {"everearn":{"usd":1.868e-05,"usd_market_cap":0.0,"usd_24h_vol":839.0915116166398,"usd_24h_change":1.5959917379692774}} Using the results above, what I would like to do is format/mask the returned data to look like this: Price: 0.00001868 (Ideally only show the decimals if needed. Some will have 8 decimal places, others will have 2, other prices will reach into xxx,xxx.xx) 24h Change: 1.59% (this could be a negative value as well) Volume: 839.09 Market Cap: 0.0
×
×
  • 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.