Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $params = array(
- 'convert' => 'INR'
- );
- $url = 'https://api.coinmarketcap.com/v1/ticker/ripple/';
- $result = sendRequest($url, $params);
- $response = json_decode($result, true);
- function sendRequest($url, $data, $user='', $pass = ''){
- $params = '';
- foreach($data as $key=>$value)
- $params .= $key.'='.$value.'&';
- $params = trim($params, '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url.'?'.$params ); //Url together with parameters
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Return data instead printing directly in Browser
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 7); //Timeout after 7 seconds
- curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($ch);
- if(curl_errno($ch)) //catch if curl error exists and show it
- return array('error' => curl_error($ch));
- else{
- curl_close($ch);
- return $result;
- }
- }
- function nice_number($n) {
- // first strip any formatting;
- $n = (0+str_replace(",", "", $n));
- // is this a number?
- if (!is_numeric($n)) return false;
- // now filter it;
- if ($n > 1000000000000) return round(($n/1000000000000), 2).' T';
- elseif ($n > 1000000000) return round(($n/1000000000), 2).' B';
- elseif ($n > 1000000) return round(($n/1000000), 2).' M';
- elseif ($n > 1000) return round(($n/1000), 2).' Thousnad';
- return number_format($n);
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Coin Market API</title>
- <!-- Latest compiled and minified CSS -->
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
- </head>
- <body>
- <table class="table table-bordered table-striped" style="width: 600px;margin: 50px auto;">
- <tr>
- <th>Name</th>
- <th>Price</th>
- <th>24h Volume USD</th>
- </tr>
- <?php foreach ($response as $key => $coins): ?>
- <tr>
- <td><?php echo $coins['name'] ?></td>
- <td>₹ <?php echo round($coins['price_inr'], 2) ?></td>
- <td>$ <?php echo nice_number( $coins['24h_volume_usd'] ) ?></td>
- </tr>
- <?php endforeach ?>
- </table>
- </body>
- </html>
Add Comment
Please, Sign In to add comment