2016-04-24 196 views
0

我想用cURL从区块链中获取比特币钱包的总美元价值。这里是我的代码:使用PHP curl从区块链中提取数据

$content2 = file_get_contents("https://blockchain.info/address/1HoB5A1HBbnB3b5gQZ6U78JzA7Hqk9WWYx?currency=USD"); 

preg_match('#<span data-c="([0-9\.]*)">$ ([0-9\.]*)</span>#Uis', $content2, $USDmatch); 

$usd = $USDmatch[0]; 

echo "Total USD: $usd"; 
+1

的[你如何解析和PHP程序的HTML/XML?(可能的复制http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html- xml-in-php) –

回答

0

您需要使用反斜杠来转义美元符号。

preg_match('#<span data-c="([0-9\.]*)">\$ ([0-9\.]*)</span>#Uis', $content2, $USDmatch); 
+0

谢谢! <3 – joeytrumann