-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> ';

本质上,您不希望每个项目都输出itemanddescription标记,因此它们属于循环之外。

于 2012-04-11T22:45:08.930 回答