在空RSS提要后显示文本

Display text after empty RSS feed

本文关键字:显示 文本 RSS 在空      更新时间:2023-09-26

我是php新手,希望有人能帮助我。
我已经能够通过从互联网上提取不同的代码来获得RSS提要并运行。
我想要实现的是,如果RSS提要是空的,我希望它显示一条消息"没有当前警告"
如果RSS提要中有条目,我希望它显示条目,以及下面设置为隐藏的div。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<title>Weather Warnings for Queensland - Issued by the Bureau of Meteorology</title></head>
<link type="text/css" href="rss-style.css" rel="stylesheet">
</head>
<script type="text/javascript">
    window.setInterval (BlinkIt, 500);
    var color = "#0000FF";
    function BlinkIt () {
        var blink = document.getElementById ("blink");
        color = (color == "#FA000C")? "#0000FF" : "#FA000C";
        blink.style.color = color;
    }
</script>
<body bgcolor="#999">
<h1>Weather Warnings for Queensland - Issued by the Bureau of Meteorology</h1>
<hr>
<br>
<!-- display current weather warnings -->
<fieldset class="rsslib">
<?php
require_once("rsslib.php");
$url = "http://www.bom.gov.au/fwo/IDZ00056.warnings_qld.xml";
    echo RSS_Display($url, 3, false,  true)
     //if there is no warning, i would like to display text saying "There are no current warnings"
    // if there are warnings, I would like it to display the RSS, and also display the below wrapper blinking text.
?>
</fieldset>

<!---------------------------- echo "There are no current weather warnings" ---------------------------------->

<!-- this is where I put my blinking text, this is not currently set to only display when there is a warning-->     
<div id='wrapper' style="display: none">
    <div id="blink">
        Current Weather Warning!
    </div>
    <div id="direction">
        Please go to www.bom.gov.au for more details.
    </div>
</div>
</body>
    </html>

任何帮助将不胜感激,我可以复制在rsslib.php如果需要吗??

调用RSS_Display时,不要立即显示它,而是将它的返回值存储在一个变量中。然后,您可以测试它是否是一个空字符串(没有显示),并采取相应的行动:

$rss = RSS_Display($url, 3, false, true);
if ($rss == '')
{
    // nothing shown, do whatever you want
}
else
{
    // something to display
    echo $rss;
    // you can add other stuff here
}