Get information from an external array / API / URL using PHP

I have a url http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132 , which leads to an array.

I want to get the value of the first " sellorders", which in this case is 0.00000048 and will store it in a variable $sellorderprice.

Can anyone help?

Thank.

+4
source share
2 answers

Just log into url content via file_get_contents. Your page actually returns a JSON string to get these values ​​into meaningful data, decode them through json_decode, and then access the relevant data:

$url = 'http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132';
$data = json_decode(file_get_contents($url), true);
$sellorderprice = $data['return']['DOGE']['sellorders'][0]['price'];
echo $sellorderprice;

0, . , , , foreach:

foreach($data['return']['DOGE']['sellorders'] as $sellorders) {
    echo $sellorders['price'], '<br/>';
}
+1

, json :

    $json = file_get_contents("http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=132");
    $arr = json_decode($json, true);
    $sellorderprice = $arr['return']['DOGE']['sellorders'][0]['price'];
+1

All Articles