2015-05-11 18 views
0

我想將一個下拉列表添加到RSS供稿解析器。如何將表單選擇選項添加到php rss供稿腳本

我有這樣的:

<fieldset class="rsslib"> 

<?php 
$cachename = "rss-cache-tmp.php"; 
$url = "http://www.theweekinchess.com/twic-rss-feed"; 

if(file_exists($cachename)) 
{ 
    $now = date("G"); 
    $time = date("G", filemtime($cachename)); 
    if($time == $now) 
    { 
     include($cachename); 
     exit(); 
    } 
} 
require_once("rsslib.php"); 
$cache = RSS_Display($url, 15, false, true); 
file_put_contents($cachename, $cache); 
echo $cache; 
?> 
</fieldset> 

但我想設置PHP中的$網址與選擇的選項,如下所示:

<?php 

$temp = $_POST["url"]; 

?> 

<form method = "post"> 
<select name="url" id="url"> 
<option value="http://www.theweekinchess.com/twic-rss-feed">TWIC</option> 
<option value="http://chesscafe.com/feed/">Chess Cafe</option> 
<option value="http://www.chessdom.com/rss">Chessdom</option> 
<option value="http://chess-news.ru/rss-eng">Chess-news</option> 
<option value="http://www.chess.com/rss/articles">chess.com</option> 
</select> 
</form> 

但我無法通過表單變量PHP腳本。我試過但我的結果很可悲,我想離開原來的代碼來簡化事情。

任何想法?

+0

只是使用'$ temp'爲您的網址裏面'RSS_Display' – Ghost

回答

0

您的表單需要一個操作。

你需要知道,如果表單提交:($子)

<?php 
$sub = intval($_POST["sub"]); 
if ($sub == 1){ 
    $url= $_POST["url"]; 
} 
else{ 
    $url = "http://www.theweekinchess.com/twic-rss-feed"; 
} 
require_once("rsslib.php"); 
$cache = RSS_Display($url, 15, false, true); 
$cachename = "rss-cache-tmp.php"; 
file_put_contents($cachename, $cache); 



// I have no idea what you are doing here or why 

if(file_exists($cachename)){ 
    $now = date("G"); 
    $time = date("G", filemtime($cachename)); 
    if($time == $now){ 
    include($cachename); 
    exit(); 
    } 
} 


echo <<<EOT 
$cache; 
<fieldset class="rsslib"> // ?????? 

</fieldset> 
<form action="#" method = "post"> 
<input type="hidden" name="sub" value="1" /> 
<select name="url" id="url"> 
<option value="http://www.theweekinchess.com/twic-rss-feed">TWIC</option> 
<option value="http://chesscafe.com/feed/">Chess Cafe</option> 
<option value="http://www.chessdom.com/rss">Chessdom</option> 
<option value="http://chess-news.ru/rss-eng">Chess-news</option> 
<option value="http://www.chess.com/rss/articles">chess.com</option> 
</select> 
</form> 
EOT; 
?> 
相關問題