简体   繁体   中英

Display text after empty RSS feed

I am new to php and hoping someone can help.
I have been able to get an RSS feed up and running by pulling different code from over the internet.
What I am trying to achieve is, if the RSS feed is empty, I would like it to display a message "There are no current warnings"
If there are items in the RSS feed, I would like it to display the Item, along with a div below that is set to hidden.

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

Any help would be much appreciated, I can copy in the rsslib.php if need be??

When you call RSS_Display , instead of displaying it immediately, store its return value in a variable. Then you can test whether it's an empty string (nothing to display) or not, and act accordingly:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM