array tekstbestand converteren
Ik heb een textbestand gevuld met een groot aantal gegevens. Het bestaat uit meerdere regels zoals hieronder er 1 staat aagegeven. Ik wil deze met php weergeven om dan selecties te kunnen maken. Ik weet hoe array's werken maar ik heb geen idee hoe ik zo'n document kan omzetten. Kan iemand mij advies geven?
Thankx
Voorbeeldregel van een regel;
Code (php)
1
{"status":{"timestamp":"2021-12-04T13:02:58.558Z","error_code":0,"error_message":null,"elapsed":22,"credit_count":1,"notice":null,"total_count":7934},"data":[{"id":1,"name":"Bitcoin","symbol":"BTC","slug":"bitcoin","num_market_pairs":8308,"date_added":"2013-04-28T00:00:00.000Z","tags":["mineable","pow","sha-256","store-of-value","state-channel","coinbase-ventures-portfolio","three-arrows-capital-portfolio","polychain-capital-portfolio","binance-labs-portfolio","blockchain-capital-portfolio","boostvc-portfolio","cms-holdings-portfolio","dcg-portfolio","dragonfly-capital-portfolio","electric-capital-portfolio","fabric-ventures-portfolio","framework-ventures-portfolio","galaxy-digital-portfolio","huobi-capital-portfolio","alameda-research-portfolio","a16z-portfolio","1confirmation-portfolio","winklevoss-capital-portfolio","usv-portfolio","placeholder-ventures-portfolio","pantera-capital-portfolio","multicoin-capital-portfolio","paradigm-portfolio"],"max_supply":21000000,"circulating_supply":18890987,"total_supply":18890987,"platform":null,"cmc_rank":1,"last_updated":"2021-12-04T13:02:02.000Z","quote":{"USD":{"price":47201.84236157637,"volume_24h":62618418378.936775,"volume_change_24h":94.4686,"percent_change_1h":1.04215459,"percent_change_24h":-17.01631179,"percent_change_7d":-13.77003006,"percent_change_30d":-23.77721437,"percent_change_60d":-5.46384951,"percent_change_90d":-5.79607754,"market_cap":891689390428.5885,"market_cap_dominance":40.5598,"fully_diluted_market_cap":991238689593.1,"last_updated":"2021-12-04T13:02:02.000Z"}}}]}
Gewijzigd op 06/12/2021 15:19:09 door - Ariën -
echo"<pre"> print_r(json_decode($response));echo"<pre"> // print json decoded response
curl_close($curl); // Close request
Dit geeft met hetzelfde overzicht, dus niet per regel onder elkaar, waarschijnlijk is de syntax niet correct?
Ga anders even stapje voor stapje debuggen ipv alle functies achter elkaar uitvoeren.
Ga ik doen!
$arr=(json_decode($response));
foreach($arr as $name){
echo $name . "<br>";
}
Geeft:Recoverable fatal error: Object of class stdClass could not be converted to string in /
Mijn kennis houd hier helaas op.
Ik vermoed dat je nog meer hebt?
Ik heb dit script uitgetest, en het werkt prima:
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
$json = '{"status":{"timestamp":"2021-12-04T13:02:58.558Z","error_code":0,"error_message":null,"elapsed":22,"credit_count":1,"notice":null,"total_count":7934},"data":[{"id":1,"name":"Bitcoin","symbol":"BTC","slug":"bitcoin","num_market_pairs":8308,"date_added":"2013-04-28T00:00:00.000Z","tags":["mineable","pow","sha-256","store-of-value","state-channel","coinbase-ventures-portfolio","three-arrows-capital-portfolio","polychain-capital-portfolio","binance-labs-portfolio","blockchain-capital-portfolio","boostvc-portfolio","cms-holdings-portfolio","dcg-portfolio","dragonfly-capital-portfolio","electric-capital-portfolio","fabric-ventures-portfolio","framework-ventures-portfolio","galaxy-digital-portfolio","huobi-capital-portfolio","alameda-research-portfolio","a16z-portfolio","1confirmation-portfolio","winklevoss-capital-portfolio","usv-portfolio","placeholder-ventures-portfolio","pantera-capital-portfolio","multicoin-capital-portfolio","paradigm-portfolio"],"max_supply":21000000,"circulating_supply":18890987,"total_supply":18890987,"platform":null,"cmc_rank":1,"last_updated":"2021-12-04T13:02:02.000Z","quote":{"USD":{"price":47201.84236157637,"volume_24h":62618418378.936775,"volume_change_24h":94.4686,"percent_change_1h":1.04215459,"percent_change_24h":-17.01631179,"percent_change_7d":-13.77003006,"percent_change_30d":-23.77721437,"percent_change_60d":-5.46384951,"percent_change_90d":-5.79607754,"market_cap":891689390428.5885,"market_cap_dominance":40.5598,"fully_diluted_market_cap":991238689593.1,"last_updated":"2021-12-04T13:02:02.000Z"}}}]}';
$array = json_decode($json,true);
print_r($array);
?>
$json = '{"status":{"timestamp":"2021-12-04T13:02:58.558Z","error_code":0,"error_message":null,"elapsed":22,"credit_count":1,"notice":null,"total_count":7934},"data":[{"id":1,"name":"Bitcoin","symbol":"BTC","slug":"bitcoin","num_market_pairs":8308,"date_added":"2013-04-28T00:00:00.000Z","tags":["mineable","pow","sha-256","store-of-value","state-channel","coinbase-ventures-portfolio","three-arrows-capital-portfolio","polychain-capital-portfolio","binance-labs-portfolio","blockchain-capital-portfolio","boostvc-portfolio","cms-holdings-portfolio","dcg-portfolio","dragonfly-capital-portfolio","electric-capital-portfolio","fabric-ventures-portfolio","framework-ventures-portfolio","galaxy-digital-portfolio","huobi-capital-portfolio","alameda-research-portfolio","a16z-portfolio","1confirmation-portfolio","winklevoss-capital-portfolio","usv-portfolio","placeholder-ventures-portfolio","pantera-capital-portfolio","multicoin-capital-portfolio","paradigm-portfolio"],"max_supply":21000000,"circulating_supply":18890987,"total_supply":18890987,"platform":null,"cmc_rank":1,"last_updated":"2021-12-04T13:02:02.000Z","quote":{"USD":{"price":47201.84236157637,"volume_24h":62618418378.936775,"volume_change_24h":94.4686,"percent_change_1h":1.04215459,"percent_change_24h":-17.01631179,"percent_change_7d":-13.77003006,"percent_change_30d":-23.77721437,"percent_change_60d":-5.46384951,"percent_change_90d":-5.79607754,"market_cap":891689390428.5885,"market_cap_dominance":40.5598,"fully_diluted_market_cap":991238689593.1,"last_updated":"2021-12-04T13:02:02.000Z"}}}]}';
$array = json_decode($json,true);
print_r($array);
?>
Zie ook de uitvoer ervan:
https://3v4l.org/c46Ti
Gewijzigd op 06/12/2021 15:20:25 door - Ariën -
Ik heb het exact zo over genomen.
Ik krijg geen foutmelding maar nu de hele layout in een blok. Hieronder een stukje als voorbeeld.
Array ( [status] => Array ( [timestamp] => 2021-12-06T14:36:56.386Z [error_code] => 0 [error_message] => [elapsed] => 17 [credit_count] => 1 [notice] => [total_count] => 7995 ) [data] => Array ( [0] => Array ( [id] => 1 [name] => Bitcoin [symbol] => BTC [slug] => bitcoin [num_market_pairs] => 8253 [date_added] => 2013-04-28T00:00:00.000Z
Je weet toch hoe array's werken?
Voor het gemak kan je het tussen <pre>-tags zetten, zodat je newlines hebt voor een beter spaghetti-loos overzicht.
Bedankt voor de support!!
Peter