Search code examples
phpcurlpreg-match

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

Solution

  • You need to use backslash to escape the dollar sign.

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