Php Laravel Display美元产品mysql比特币交换价格

Php Laravel Display美元产品mysql比特币交换价格,php,mysql,laravel-5,Php,Mysql,Laravel 5,我有一个liitle商店,里面的产品的所有价格都是比特币,Mysql数据库也采用这种格式: {{$product->buyout*0.00000001}} @else {{$product->price*0.00000001}} 现在我想用Curl显示数据库中的比特币价格,单位为美元 最好的方法是什么 我已经用这个代码试过了,还有其他的工作思路吗 <?php $url = "https://bitpay.com/api/rates"; $json = file_

我有一个liitle商店,里面的产品的所有价格都是比特币,Mysql数据库也采用这种格式:

{{$product->buyout*0.00000001}} @else {{$product->price*0.00000001}}
现在我想用Curl显示数据库中的比特币价格,单位为美元

最好的方法是什么

我已经用这个代码试过了,还有其他的工作思路吗

<?php  
  $url = "https://bitpay.com/api/rates";

  $json = file_get_contents($url);
  $data = json_decode($json, TRUE);

  $rate = $data[1]["rate"];    
  $bitcoin_price = 0.008;    
  $usd_price = round( $bitcoin_price / $rate , 8 );
?>

<ul>
   <li>Price: <?=$bitcoin_price ?> BTC / <?=$usd_price ?> USD
</ul>

  • 价格:BTC/美元