简体   繁体   English

在XML页面中使用PHP进行RSS

[英]Use PHP in XML page for rss

I would like to know if it is possible to use Php coding in a xml page that is used for rss. 我想知道是否有可能在用于rss的xml页面中使用Php编码。 Basically I want to connect to mysql database and pull out information to be in the rss feed as shown; 基本上,我想连接到mysql数据库并提取信息以显示在rss feed中;

while($r = mysql_fetch_object($sql_rss)){

    $post_title = $r->title;
    $post_post = $r->thepost;
    $post_link = $r->thelink;

    $received_posts .= '
<title>'.$post_title.'</title>
<link>'.$post_link.'</link>
<description>'.$post_post.'</description>';

Would I need to do anything special to use php in a xml script? 我需要做一些特殊的事情才能在xml脚本中使用php吗? Thanks in advanced. 提前致谢。

只要确保服务器正在为PHP指令处理文件(可能通过在文件名末尾使用.php )并设置Content-Type(因为它默认为HTML)即可。

header('Content-Type: application/rss+xml');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM