Answer the question
In order to leave comments, you need to log in
How to correctly process received data from json string from cURL?
the essence
is this, there is a site that gives out information from its database in this form ,"last":7556.195,"buy":7556.915,"sell":7550,"updated":1521400547}}
I need to create a class in which from this line there will be variables high, low, buy, sell with values from this line
<?php
//выбор валюты
$currency_1 = 'btc';
$currency_2 = 'usd';
$cur = $currency_1.'_'.$currency_2;
parsing($cur);
function parsing($cur){
$target_url = 'https://wex.nz/api/3/ticker/'.$cur;
$ch = curl_init($target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$json_string = (string)$res;
$arr = json_decode($json_string,true)
echo $arr->['high'];
echo '<br/>';
echo '<br/>';
var_dump(json_decode($json_string,true));
echo $json_string.'<br/>';
}
Answer the question
In order to leave comments, you need to log in
You need to understand the basic concepts of the language you are working with. What is an object in PHP and what is an array? How to work with them? Spend a few evenings looking through the documentation.
echo $arr['btc_usd']['high']; // для понимания
echo $arr[$cur]['high']; // правильный вариант
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question