-1

我知道我的代码很乱,我对此很陌生,并且正在学习。

我的网站是这样的:http: //itsalllegit.com(目前在我的家用电脑上运行并使用 tvdb api,所以有时它有点慢)。

大部分似乎都有效,目前唯一无效的是 NCIS,如下所示:http: //itsalllegit.com/season.php ?sid=72108&season=1 。

我知道它很糟糕而且很长,但这是我的代码......我一直在努力解决这个问题,非常感谢您的帮助(一般来说,任何关于使它变得更好的提示也是如此)。

顺便说一句...如果我echo $url3想出"(*#YR&(^#R(@$#%$&^@#%$*@#%$&^@$#&"等等。

    <html>
    <head>
        <title>Saars - Homepage</title>
            <link rel="stylesheet" type="text/css" href="default.css" />
    </head> 
        <body>
            <?php

                $series_id = $_GET["sid"];
                $season_number = $_GET["season"];
                $local_path = "images/Banner/".$series_id."-Banner.jpg";
                $url1 = file_get_contents("http://thetvdb.com/api/E676DF9578EF38D7/series/".urlencode($series_id));
                $xml = simplexml_load_string($url1);
                $series_name = $xml->Series[0]->SeriesName;
                $series_rating = $xml->Series[0]->Rating;
                $series_network = $xml->Series[0]->Network;
                $series_status = $xml->Series[0]->Status;
                    echo '<img src="'.$local_path.'"><br />';
                    echo "Name: ".$series_name."<br />";
                    echo "Rating: ".$series_rating."<br />";
                    echo "Network: ".$series_network."<br />";
                    echo "Status: ".$series_status."<br />";
                    echo "<hr />";
                        echo '<table bgcolor="#000000">';
                            echo '<tr>';
                                echo '<td width="30">';
                                    echo '<font color="white">#</font>';
                                echo '</td>';
                                echo '<td width="500">';
                                    echo '<font color="white">Episode Name</font>';
                                echo "</td>\n";
                                echo '<td width="100">';
                                    echo '<font color="white">First Aired</font>';
                                echo "</td>\n";
                            echo "</tr>\n";
                        echo "</table>";
                for ($episode_number = 1; $episode_number <= 200; $episode_number++) {
                    $url2 = "http://thetvdb.com/api/E676DF9578EF38D7/series/".$series_id."/default/".urlencode($season_number)."/".urlencode($episode_number)."/en.xml";
                    $handle = @fopen($url2, 'r');
                    if ($handle === false) {
                        return;
                    } else {
                        $url3 = file_get_contents("http://thetvdb.com/api/E676DF9578EF38D7/series/".$series_id."/default/".urlencode($season_number)."/".urlencode($episode_number)."/en.xml");
                        $xml = simplexml_load_string($url3);
                        $episode_name = $xml->Episode[0]->EpisodeName;
                        $episode_rating = $xml->Episode[0]->Rating;
                        $episode_firstaired = $xml->Episode[0]->FirstAired;
                        $episode_overview = $xml->Episode[0]->Overview;
                        $column1 = '<a href="episode.php?sid='.$series_id.'&season='.$season_number.'&episode='.$episode_number.'">'.$episode_number.'</a>';
                        $column2 = '<a href="episode.php?sid='.$series_id.'&season='.$season_number.'&episode='.$episode_number.'">'.$episode_name.'</a>';
                        $column3 = '<a href="episode.php?sid='.$series_id.'&season='.$season_number.'&episode='.$episode_number.'">'.$episode_firstaired.'</a>';
                            echo '<table>';
                                echo "<tr>\n";
                                    echo '<td width="30">';
                                        echo $column1;
                                    echo "</td>\n";
                                    echo '<td width="500">';
                                        echo $column2;
                                    echo "</td>\n";
                                    echo '<td width="100">';
                                        echo $column3;
                                    echo "</td>\n";
                                echo "</tr>\n";
                            echo "</table>";
                    fclose($handle);
                    }
                }
                ?>
        </Body>
    </html>
4

1 回答 1

0

您打开每个 URL 两次,但只读取一次数据。服务器可能会拒绝这种行为作为猛击并在一段时间后拒绝第二个连接。尝试将循环的内容更改为:

// Define the URL
$url2 = "http://thetvdb.com/api/E676DF9578EF38D7/series/$series_id/default/".urlencode($season_number)."/".urlencode($episode_number)."/en.xml";

// Try and fetch the XML
// You are returning a value - are you in a function? Should you maybe break; instead?
if (!$xmlStr = file_get_contents($url2)) return FALSE;
if (!$xml = simplexml_load_string($xmlStr)) return FALSE;

// Get data
$episode_name = $xml->Episode[0]->EpisodeName;
$episode_rating = $xml->Episode[0]->Rating;
$episode_firstaired = $xml->Episode[0]->FirstAired;
$episode_overview = $xml->Episode[0]->Overview;

// Output HTML
// A single-row table per record? Maybe you should have one table with multiple rows?
$epURL = htmlspecialchars("episode.php?sid=$series_id&season=$season_number&episode=$episode_number");
echo "
<table>
  <tr>
    <td width='30'><a href='$epURL'>$episode_number</a></td>
    <td width='500'><a href='$epURL'>$episode_name</a></td>
    <td width='100'><a href='$epURL'>$episode_firstaired</a></td>
  </tr>
</table>";

如果它仍然不起作用,请尝试$url2在循环中回显,以查看出现错误时包含的内容。

于 2012-04-12T11:49:30.440 回答