-1

私はいくつかの問題を引き起こしている次のコードを持っています

<?PHP
 include("../panel/config.php");
 #// Timetable Clearup Variabls
$yesterday = strtotime('yesterday');
$yesterdow = date('l',$yesterday);
$order = "SELECT * FROM timetable WHERE day = '$yesterdow' ORDER BY time";
$result = mysql_query($order);
$yesterdayd = date('F jS, Y', time()-86400);

    //SET XML HEADER
    header('Content-type: text/xml');

    //CONSTRUCT RSS FEED HEADERS
    $output = '<rss version="2.0">';
    $output .= '<channel>';
    $output .= "<title>Timetable - {$yesterdayd} </title>";
    $output .= '<description>Timetable.</description>';
        $output .= '<link>www.site.com</link>';
     while ($row = mysql_fetch_array($result)) {
    //BODY OF RSS FEED
   $output .= '<item>';
     $output .= "<description>" . htmlspecialchars($row['time']) . " " . htmlspecialchars($row['username']) . "</description>";
   $output .= '</item> ';
 }
    //CLOSE RSS FEED
   $output .= '</channel>';
   $output .= '</rss>';

    //SEND COMPLETE RSS FEED TO BROWSER
$filename = "timetable.xml";

                if (!$handle = fopen($filename, 'w')) {
            echo "Cannot open file ($filename)";
            exit;
            }

            // Write $somecontent to our opened file.
            if (fwrite($handle, $output) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
            }

            if (fwrite($handle, $total) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
            }

            echo "Success, wrote {$content}{$total} to file ($filename)";

            fclose($handle);


?>

これにより、.xml rss フィードが作成されますが、すべてが独自のものであり、問​​題<item></item><description></description>発生します。<item><discussion>すべてのコンテンツをラップする方法はありますか</discussion></item>

ありがとう

4

1 に答える 1

0

ループを次のように変更します。

$output .= '<item><description>';
while ($row = mysql_fetch_array($result))
{
  //BODY OF RSS FEED
  $output .= htmlspecialchars($row['time']) . " " . htmlspecialchars($row['username']) . "<br/>";
}
$output .= '</description></item> ';

item基本的に、 andタグがすべての項目で出力されるのは望ましくないdescriptionため、それらはループの外に属します。

于 2012-04-11T22:45:08.930 に答える