joeytrumann joeytrumann - 7 months ago 16
PHP Question

Extracting data from blockchain using PHP curl

I am trying to grab the total USD value of a bitcoin wallet from blockchain using cURL. Here is my code:

$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 Donated: $usd";


I can't seem to figure it out. Any thoughts? I got it working for Bitcoin but for some reason it won't work for USD.

Answer

You need to use backslash to escape the dollar sign.

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