4

I have the 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 store it in the variable $sellorderprice.

Can anyone help?

Thanks.

1
  • Try using json_decode($output); it will convert a json string to an array format. Commented Apr 18, 2015 at 8:14

2 Answers 2

2

Just access the url contents thru file_get_contents. Your page actually return a JSON string, to get those values into meaningful data, decode it thru json_decode, after that access the data needed accordingly:

$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;

That code actually points directly to index zero 0 which gets the first price. If you need to get all items an just simply echo them all you need to iterate all items thru foreach:

foreach($data['return']['DOGE']['sellorders'] as $sellorders) {
    echo $sellorders['price'], '<br/>';
}
Sign up to request clarification or add additional context in comments.

Comments

1

Its simple, you just have to decode json like this:

    $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'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.