0

我有一个 RSS 提要,由于某种原因没有显示我的 PHP 变量。返回提要时,它会返回原始标签,例如标题将是 Timetable $yesterdayd 而不是 Timetable - 4 月 10 日星期二

<?PHP
 include("../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>http://site.com/</link>';
 ###   $output .= '<copyright>Your copyright details</copyright>';

    //BODY OF RSS FEED
   $output .= '<item>';
        $output .= '<title>Timetable for $yesterdayd</title>';
        $output .= '<description>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</description>';
        $output .= '<link>Link to Item</link>';
        $output .= '<pubDate>Date Published</pubDate>';
   $output .= '</item> ';

    //CLOSE RSS FEED
   $output .= '</channel>';
   $output .= '</rss>';

    //SEND COMPLETE RSS FEED TO BROWSER
    echo($output);

?>

有任何想法吗?

4

2 回答 2

2

对输出字符串使用双引号。我认为变量不会插入单引号。

所以喜欢

$output .= "<title>Timetable for $yesterdayd</title>";

那应该这样做。该页面确实有一个 php 扩展名,对吗?

编辑:

当你插入数组或对象时,使用像 {$row['username']} 或 {$object->property} 这样的语法,但是当你调用一个函数时,你不能插入,你必须连接:

"<description>" . htmlspecialchars($row['username']) . "</td>";

此外,请确保您现在没有混合单引号和双引号 - 看起来您作为响应粘贴的代码混合了它们。

于 2012-04-11T19:33:49.757 回答
0

单引号字符串不会计算 php 变量。

IE

'<title>Timetable - $yesterdayd </title>';

应该

"<title>Timetable - {$yesterdayd} </title>";
于 2012-04-11T19:34:07.173 回答