PHP如何将btc转换为美元
我想在PHP中创建一个将比特币转换为美元的函数,下面是我的代码:PHP如何将btc转换为美元,php,Php,我想在PHP中创建一个将比特币转换为美元的函数,下面是我的代码: <?php function usd2btc($btc) { $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLO
<?php
function usd2btc($btc) {
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "spider",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 2,
CURLOPT_SSL_VERIFYPEER => false
);
$ch = curl_init( "https://api.coingate.com/v2/rates/merchant/BTC/USD" ); //BTC2USD exange
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch ); // Gets the page's content
$err = curl_errno( $ch ); // Gets the CURL error number if there is error
$errmsg = curl_error( $ch ); // Gets the CURL error text if there is error
curl_close( $ch );
if ($btc !== 0) {
return round($btc/$content, 2);
} else {
return 0.00;
}
}
?>
请求似乎没有成功。您是否尝试回显$errmsg
?我尝试删除curl\u setopt\u数组($ch,$options)
从代码中,现在函数只返回比特币值,忽略除法,$errmsg
不输出任何内容。
<p>0.002฿ = <?php htmlspecialchars(usd2btc(0.002)); ?>$</p>