Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP foreach没有在JSON文件中循环_Php_Json_Loops_Foreach - Fatal编程技术网

PHP foreach没有在JSON文件中循环

PHP foreach没有在JSON文件中循环,php,json,loops,foreach,Php,Json,Loops,Foreach,foreach函数未在此JSON文件上运行 我希望PHP遍历JSON文件并以HTML表格格式输出数据 <?php // Store JSON data in a PHP variable $url = 'https://eztv.io/api/get-torrents?limit=100&page=1'; // path to your JSON file $data = file_get_contents($url); // put the contents of the fil

foreach
函数未在此JSON文件上运行

我希望PHP遍历JSON文件并以HTML表格格式输出数据

<?php
// Store JSON data in a PHP variable
$url = 'https://eztv.io/api/get-torrents?limit=100&page=1'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
//var_dump(json_decode($data));
$shows = json_decode($data, true); // decode the JSON feed and make an associative array
?>
<br /><br /><br /><br />

<table>
<?php
foreach ($shows as $shows) : ?>
    <tr>
        <td> <strong><?php echo $shows["title"] . "\n"; ?></strong>  </td>
        <td> <strong><?php echo $shows["season"] . "\n"; ?></strong>  </td>
        <td> <strong><?php echo $shows["episode"] . "\n"; ?></strong>  </td>
        <td> <a href="<?php echo $shows["magnet_url"] . "\n"; ?>">magnet</a></td>
        <td> <?php echo $shows["date_released_unix"] . "\n"; ?>  </td>
        <td> <?php echo $shows["size_bytes"] . "\n"; ?>  </td>
        <td> <a href="<?php echo $shows["episode_url"] . "\n"; ?>">episode Link</a></td>
        <td> <?php echo $shows["imdb_id"] . "\n"; ?>  </td>
    </tr>
<?php endforeach; ?>
</table>







如果我运行此代码,我会在页面上看到一个
注意:未定义索引:
错误。

响应的
torrents
键处的所有数据。 您应该检查数组索引/键是否存在

<?php 
$url = 'https://eztv.io/api/get-torrents?limit=100&page=1'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$shows = json_decode($data, true); // decode the JSON feed and make an associative array 
<?php foreach ($shows['torrents'] as $shows) : ?>
    <tr></tr>
<?php endforeach; ?>

foreach($shows显示为$shows):?>




与Shivendra Singh的回答类似,但我们使用空合并只是为了让阅读更容易。

我们不知道json字符串是如何链接到json的,或者我应该在这里发布它吗?不要使用链接,发布json文件(如果它很大,则发布我们需要阅读的部分以帮助您)
foreach ($shows as $shows) : ?>
    <tr>
        <td> <strong><?php echo $shows["title"] ?? '' . "\n"; ?></strong>  </td>
        <td> <strong><?php echo $shows["season"] ?? '' . "\n"; ?></strong>  </td>
        <td> <strong><?php echo $shows["episode"] ?? '' . "\n"; ?></strong>  </td>
        <td> <a href="<?php echo $shows["magnet_url"] ?? '' . "\n"; ?>">magnet</a></td>
        <td> <?php echo $shows["date_released_unix"] ?? '' . "\n"; ?>  </td>
        <td> <?php echo $shows["size_bytes"] ?? '' . "\n"; ?>  </td>
        <td> <a href="<?php echo $shows["episode_url"] ?? '' . "\n"; ?>">episode Link</a></td>
        <td> <?php echo $shows["imdb_id"] ?? '' . "\n"; ?>  </td>
    </tr>
<?php endforeach; ?>