我連接到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