我是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中吗?
答案 0 :(得分:1)
当您致电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
}