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


How to link RSS feed created in php mysql

我在php中创建了一个RSS提要php文件,该文件连接到MySQL。基于ID,如果您点击RSS链接,它将为每个人生成RSS提要。但是我想知道如何将我的RSS提要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>

第一步:

你需要创建一个php文件,比如generate.php,它接受一个GET参数feedId:

// 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>