Question

I'm a fan of Bitcoins and all other alternative coins, so what I am trying to make is a page with all my coins I own, and shows the latest value of each coin.

So what I've got so far is a cURL that gets the content of a website, in this case it is cryptorush.in. The output of the cURL is:

21 / BTC 
13.22000001 

42 / BTC 
112.10000000 

Etc.

So I thought it would be a nice way to recognize "21 / BTC" for example and read the latest value at the next line. $curlPage is my cURL page.

if (strpos($curlPage,'21 / BTC') !== false) { 
//do something
} 

Output:

13.22000001

But I really have no idea on how to do this, so I hope anyone could answer my question.

No correct solution

OTHER TIPS

You can use a combination of regexp and the explode function. Please note that this is dependent upon the actual coding of the page you are requesting with cURL, as I am looking at the values being exploded by two returns - \n\n

$curlPage = "21 / BTC \n13.22000001\n\n42 / BTC \n112.10000000";

$arr = explode("\n\n", $curlPage);

foreach($arr as $key)
{
    list($top, $bottom) = explode("\n", $key);
    $top = preg_replace("/[^0-9]/", "", $top);

    if($top == "21") echo($bottom);
}

The first line shows what my value for $curlPage is (for testing it). This should be equal to the contents of the page (provided the contents are what you posted and each section is separated by two line breaks (\n\n)

The two important variables in the foreach() statement is $top and $bottom. $top will be equal to the number, like 21. And the $bottom variable will be equal to the bottom number like 13.22000001

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top