我连接到traileraddicts api,但是当我将页面加载到服务器时,我收到此消息。连接到卷曲和显示api
注意:尝试在第20行的/heima/sth132/.public_html/Lokaverkefnireal/php/trailers.php中获取非对象的属性警告:为/ usima/sth132 /.public_html中的foreach()提供的无效参数/Lokaverkefnireal/php/trailers.php在线20
这里是我的代码,你可以帮我解决这个问题吗?
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://api.traileraddict.com/?featured=yes&count=8");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
// load the previously downloaded XML page
$upcoming = simplexml_load_string($output);
foreach($upcoming->trailer as $x => $updates)
{
echo $updates->title;
echo '<br>';
echo '<span style="font-size:x-small">Source: <a href="'. $updates->link .'">TrailerAddict</a></span>';
echo '<br>';
//now echo the embedded trailer
echo $updates->embed;
echo '<br><br>';
}
?>
没有那dosent工作感谢虽然 – jonjonson
@jonjonson你得到什么错误?因为我已经调试过它并通过上述解决方案获得了解决方案。 – Parixit