英文:
Formatting multilevel JSON data in PHP from remote file [SOLVED]
问题
以下是您提供的内容的翻译部分:
resc_payouts.php
{"number":1,"username":"ivalenel"},{"number":2,"username":"newb-6763"},{"number":3,"username":"jeremyhipps"},{"number":4,"username":"dcollier200"},{"number":5,"username":"AdrianEric311"},{"number":6,"username":"Prxnce24"},{"number":7,"username":"Bungy2004"},{"number":8,"username":"sevyf7"},{"number":9,"username":"jerocker79"},{"number":10,"username":"Djmoonknight8"},{"number":11,"username":"marcel_g_l"},{"number":12,"username":"zebuss"},{"number":13,"username":"fourZer0"},{"number":14,"username":"himalayabpatel"},{"number":15,"username":"Chip1234"},{"number":16,"username":"AsvpJ9k"},{"number":17,"username":"himmy23"},{"number":18,"username":"Chip1234"},{"number":19,"username":"Clares20"},{"number":20,"username":"ballermoss"},{"number":21,"username":"gareagan04"},{"number":22,"username":"cweatherfordinc"}
jsontest.php
<?php
$content = file_get_contents('https://**********.com/manage/resc_payouts.php');
$decoded_json = json_decode($content, true);
foreach($decoded_json as $key => $value) {
$username = $decoded_json[$key]["username"];
echo $username;
}
?>
希望这有助于您提取远程PHP文件中的JSON数据并格式化它。
英文:
I am trying to extract json data from a remote php file (not a json file) so that it each time the page is propagated it pulls the newest data to format. Here are examples of what I am trying to accomplish but I cant get it to work.
resc_payouts.php
{"number":1,"username":"ivalenel"},{"number":2,"username":"newb-6763"},{"number":3,"username":"jeremyhipps"},{"number":4,"username":"dcollier200"},{"number":5,"username":"AdrianEric311"},{"number":6,"username":"Prxnce24"},{"number":7,"username":"Bungy2004"},{"number":8,"username":"sevyf7"},{"number":9,"username":"jerocker79"},{"number":10,"username":"Djmoonknight8"},{"number":11,"username":"marcel_g_l"},{"number":12,"username":"zebuss"},{"number":13,"username":"fourZer0"},{"number":14,"username":"himalayabpatel"},{"number":15,"username":"Chip1234"},{"number":16,"username":"AsvpJ9k"},{"number":17,"username":"himmy23"},{"number":18,"username":"Chip1234"},{"number":19,"username":"Clares20"},{"number":20,"username":"ballermoss"},{"number":21,"username":"gareagan04"},{"number":22,"username":"cweatherfordinc"}
jsontest.php
<?php
$content = file_get_contents('https://**********.com/manage/resc_payouts.php');
$decoded_json = json_decode($content, true);
foreach($decoded_json as $key => $value) {
$username = $decoded_json[$key]["username"];
echo $username;
}
?>
I have tried many methods, converting to a string, encoding and then decoding but cant seem to figure this out. Any help on getting this remote data off a php file and formatting it would be immensely useful.
答案1
得分: 1
SOLUTION FOUND
<?php
$content = file_get_contents('https://**********.com/manage/resc_payouts.php');
$json = json_decode($content, TRUE); // decode the JSON into an associative array
foreach ($json as $key => $value) {
echo $value['number'];
echo $value['username'];
echo "<br/>";
}
?>
Thanks but i figured this out myself over time
英文:
So after a few hours i found a solution
SOLUTION FOUND
<?php
$content = file_get_contents('https://**********.com/manage/resc_payouts.php');
$json = json_decode($content, TRUE); // decode the JSON into an associative array
foreach ($json as $key => $value) {
echo $value['number'];
echo $value['username'];
echo "<br/>";
}
?>
Thanks but i figured this out myself over time
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论