gpt4 book ai didi

php - 使用 PHP 生成 XML 文件

转载 作者:行者123 更新时间:2023-11-29 05:36:30 25 4
gpt4 key购买 nike

我目前有一个 PHP 脚本,它在运行时输出一个 XML 文件(但是作为 feed.php 而不是 feed.xml)我被告知将其添加到我的 .htaccess 中并且它应该修复它:

AddType application/x-httpd-php .xml

但是由于某些原因,它不起作用。

我最希望脚本执行的操作是在运行时生成一个包含其内容输出的 feed.xml 文件,而不是仅在 php 页面上输出内容。

这是我的代码:

<?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>';
while ($row = mysql_fetch_array($result)) {
//BODY OF RSS FEED
$output .= '<item>';
$output .= "<description><td>" . htmlspecialchars($row['username']) . "</td><td>" . htmlspecialchars($row['time']) . "</td></description>";
$output .= '</item> ';
}
//CLOSE RSS FEED
$output .= '</channel>';
$output .= '</rss>';

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

?>

最佳答案

我建议不要在 .htaccess 中添加 .xml 以使用 PHP 编译器进行处理。而是使用 mod_rewrite 将对 .xml 文件的请求重定向到 php 脚本。

例如:

RewriteEngine On
RewriteRule ^(.*)\.xml$ /rss_feed.php [L,QSA]

关于php - 使用 PHP 生成 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10113786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com