如何链接在php mysql中创建的RSS feed

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何链接在php mysql中创建的RSS feed相关的知识,希望对你有一定的参考价值。

我在php中创建了一个连接到mysql的RSS feed php文件。根据ID,如果您点击RSS链接,它将为每个人生成RSS源。但我想知道如何将我的RSS feed php文件链接到RSS链接。这是我的PHP文件代码:

<html>
<head>
<title>New Feed</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
</head>
<body>
<?php
Function NewFeed($DingoID,$TITLE,$NOTE,$DATE,$LINK){

    $SQLString="SELECT Dingoid FROM rahul_tbl_users";
    switch ($DingoID){
        case "AllUsers":
            break;
        case "AdminUsers":
            $SQLString.=" WHERE Usertype='Admin'";
            break;
        default:
            $SQLString.=" WHERE Dingoid='".$DingoID."'";
            break;
    }
    $Ergebnis=mysql_query ($SQLString);
    $Datensatz=mysql_fetch_array($Ergebnis);
    if ($Datensatz){
        while ($Datensatz){
            $DingoID=$Datensatz["Dingoid"];

            $SQLString="INSERT INTO TblNotifications (DingoID,Title,Note,Date,Link) VALUES('".$DingoID."','".$TITLE."','".$NOTE."','".$DATE."','".$LINK."')";
            $Ergebnis3=mysql_query ($SQLString) or die("IDD-Feeds: Feed nicht eingetragen");
            //echo $SQLString;
            //echo $Ergebnis3;
            //echo ("Hier sind wir in der Function 'NewFeed'");
            $xml = new DOMDocument('1.0', 'UTF-8');
            $xml->formatOutput = true;
            //echo "Vor Create Element";
            $roo = $xml->createElement('rss');
            // "Nach Create Element";
            $roo->setAttribute('version', '2.0');
            $xml->appendChild($roo);

            $cha = $xml->createElement('channel');
            $roo->appendChild($cha); 

            $hea = $xml->createElement('title',
                utf8_encode('IDD-RSS'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('description',
                utf8_encode('IDD Request Feeds'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('language',
                utf8_encode('en'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('link',
                htmlentities('http://intranet.siemens-enterprise.com/sitecore/content/Home/Intranet/organization/sales/global-sales-operations/global-bid-management/international-cross-border-group/international-deal-desk'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('lastBuildDate',
                utf8_encode(date("D, j M Y H:i:s ").'CET'));
            $cha->appendChild($hea);


            $SQLString2="SELECT * FROM TblNotifications WHERE DingoID='".$DingoID."' ORDER BY Date";
            //echo $SQLString;
            $Ergebnis2=mysql_query ($SQLString2) or die("IDD-Feeds: Keine Daten aus dem Notification-File");
            $Datensatz2=mysql_fetch_array($Ergebnis2);
            if ($Datensatz2){
                while ($Datensatz2){
                    $itm = $xml->createElement('item');
                    $cha->appendChild($itm);
                    $dat = $xml->createElement('title',utf8_encode($Datensatz2["Title"]));
                    $itm->appendChild($dat);
                    $dat = $xml->createElement('description',utf8_encode($Datensatz2["Note"]));
                    $itm->appendChild($dat);   
                    $dat = $xml->createElement('link',htmlentities($Datensatz2["Link"]));
                    $itm->appendChild($dat);
                    $dat = $xml->createElement('pubDate',utf8_encode($Datensatz2["Date"]));
                    $itm->appendChild($dat);
                    $dat = $xml->createElement('guid',utf8_encode($Datensatz2["FeedID"]));
                    $itm->appendChild($dat);
                    $Datensatz2=mysql_fetch_array($Ergebnis2);
                }
            }
            //echo "Jetzt wird dann das xml-File geschrieben mit: ".$DingoID;
            $xml->save('../feeds/'.$DingoID.'.rss');
            $Datensatz=mysql_fetch_array($Ergebnis);
        }
    }
}
?>
</body>

</html>

我想将这个PHP代码链接到RSS链接,以便RSS提要工作。以下是我的RSS源链接:

<?php
if(!isset($_SESSION))
{

session_start();
$dingo=$_SESSION['dingo'];

}
?>

<ul>
All feeds are populated even if the Email has been deactivated.Your feeds are:
<li>
 <label for="g_feed_browser"><a style="color:black; text-decoration:none" href="http://rss.groups.yahoo.com/group/rss-board/<?php echo $dingo; ?>"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe to your personal/group HTTP feed via browser: </a></label>
</li> <br>
<li>
 <label for="g_feed_outlook"><a style="color:black; text-decoration:none" href="feed://rss.groups.yahoo.com/group/rss-board/rss"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe to your personal/group feed using Outlook : </a></label>
</li><br>
IDD General rss feeds are as follows:<br>
<li>
 <label for="idd_feed_browser"><a style="color:black; text-decoration:none" href="http://feeds.rssboard.org/rssboard"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe IDD HTTP feed via browser: </a></label>
</li><br>
<li>
 <label for="idd_feed_outlook"><a style="color:black; text-decoration:none" href="http://feeds.rssboard.org/rssboard"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe to IDD feed using Outlook: </a></label>
</li>
</ul>
答案

步骤1:

你将不得不创建一个php文件,让我们说接受GET param generate.phpfeedId

// grab feed id from $_GET
if(!isset($_GET['feedId'])) {
    header('HTTP/1.1 400 Bad Request');
    echo 'You have been missing the feed id';
    die();
}
$feedId = $_GET['feedId'];

// now generate the *feed* depending on feed id
switch ($feedId) {
    case 'feed1' :
        header('Content-Type: application/rss');
        // generate feed here
        echo 'feed1';
        break;

    case 'feed2' :
        header('Content-Type: application/rss');
        // generate feed here
        echo 'feed1';

    default :
        header('HTTP/1.1 404 Not found');
        echo 'The document you were searching for was not found';
        die();
}

您可以使用以下链接:

<a href="http://server/generate.php?feedId=feed1">feed 1</a>
<a href="http://server/generate.php?feedId=feed2">feed 2</a>

在第二个可选步骤中,您可以在.htaccess文件中使用重写规则,如下所示:

RewriteEngine On   
RewriteRule ^feeds/(.*).rss/?$ generate.php?feedId=$1

现在你的链接看起来像:

<a href="http://server/feeds/feed1.rss">feed 1</a>
<a href="http://server/feeds/feed2.rss">feed 2</a>

以上是关于如何链接在php mysql中创建的RSS feed的主要内容,如果未能解决你的问题,请参考以下文章

在另一个标签中打开rss供稿链接

我们如何在 MySQL 工作台模式部分查看在 phpmyadmin 中创建的数据库/表?

Navicat 8 for MySQL中创建的表为啥在mysql数据库中没有

MySQL:如何将当前 select 语句中创建的两个字段的结果相加?

Facebook使用简单的Pie-RSS和PHP检索最近的Facebook帖子

在 PHP 中,为啥可以在同一类类型的方法中创建的新实例上调用私有方法? [复制]