2013-06-04 39 views
0

我已經在PHP中創建了一個RSS提要php文件,它已連接到MySQL。基於ID,如果你點擊RSS鏈接,它會爲每個人生成一個RSS源。但我想知道如何將我的RSS feed php文件鏈接到RSS鏈接。這裏是我的PHP文件代碼:如何鏈接在PHP中創建的RSS提要mysql

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

回答

0

第1步:

你必須創建一個PHP文件,可以說generate.php接受一個GET PARAM 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> 
+0

不,我只是想知道我怎麼可以在我的RSS PHP文件鏈接到本RSS鏈接 –

+0

你可以嘗試進一步解釋嗎?我不明白 – hek2mgl

+0

其實我創建了這個RSS PHP文件,當我運行這個程序其運行fine.But現在爲用戶我創建了href鏈接,當用戶點擊鏈接的RSS提要應該生成。所以我只是想知道如何將我的RSS PHP文件附加到這些鏈接。因此,用戶將知道他們想要生成哪些RSS源。 –