我正在连接到traileraddicts api,但当我将页面加载到服务器时,我收到此消息。
注意:尝试在第20行的/heima/sth132/.public_html/Lokaverkefnireal/php/trailers.php中获取非对象的属性警告:在/heima/sth132/.public_html/中为foreach()提供的参数无效第20行的Lokaverkefnireal / php / trailers.php
这是我的代码,你能帮助我解决这个问题吗?
<?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>';
}
?>
答案 0 :(得分:0)
您应该将curl网址协议从https
更改为http
// set url
//please remove https
curl_setopt($ch, CURLOPT_URL, "http://api.traileraddict.com/?featured=yes&count=8");
答案 1 :(得分:0)
问题似乎来自您正在卷曲的网址,请尝试将https更改为http,这对我有用
curl_setopt($ch, CURLOPT_URL, "http://api.traileraddict.com/?featured=yes&count=8");