“如何修复错误“警告:第17行的C:\ xampp \ htdocs \ php_projekt \ programming_news.php中为foreach()提供的无效参数”

时间:2019-07-16 15:02:06

标签: php json curl

<?php
$redditKlijent = curl_init('https://www.reddit.com/r/programming/hot.json');

curl_setopt($redditKlijent, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($redditKlijent, CURLINFO_HEADER_OUT, true);
curl_setopt($redditKlijent, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json'
));

$postovi = curl_exec($redditKlijent);
$postovi = json_decode($postovi, true); 


curl_close($redditKlijent);
print '<h3>POSTOVI IZ /R/PROGRAMMING</h3><ul>';

    foreach($postovi['data']['children'] as $post) {
print '<li><a href="">' . $post['data']['title'] . '</a></li>';
}
print '</ul>';?>

0 个答案:

没有答案