如何为PHP RSS提要脚本添加表单选择选项



我正在尝试将下拉列表添加到RSS Feed Parser。

我有这个:

<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中的$ URL:

<?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脚本。我尝试过,但结果很可悲,我想留下原始代码来简化事情。

有什么想法?

您的表格需要操作。

您需要知道是否提交表格:($ sub)

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

最新更新