这个php字符串有什么问题

时间:2014-06-28 05:01:38

标签: php

我是php新手,试图让RSS阅读器在没有任何内容显示时显示消息。

我昨天请求了一些帮助,并得到了很好的帮助,这是有道理的,但由于某种原因它不存储它。

希望有人能告诉我以下php有什么问题。

<?php
require_once("rsslib.php");
$url = "http://www.bom.gov.au/fwo/IDZ00063.warnings_land_qld.xml";
$rss123 = RSS_Display($url, 3, false, true);

if (count($rss123) < 1) 
{  
              // nothing shown, do whatever you want
    echo 'There are no current warnings';
echo '<style type="text/css">
    #flashing_wrapper {
        display: none;
    }
</style>';  
}

  else
{
// something to display
echo $rss123;

}
?>

我的问题是,它似乎没有在$ rss123中存储一个值。

可以在以下地址查看 - http://goo.gl/12XQSe

先谢谢了,

皮特

-----编辑------

根据评论中的要求,RSS_Display来自rsslib.php文件,如下所示

<?php
/*
    RSS Extractor and Displayer
(c) 2007-2010  Scriptol.com - Licence Mozilla 1.1.
rsslib.php

Requirements:
- PHP 5.
- A RSS feed.

Using the library:
Insert this code into the page that displays the RSS feed:

<?php
require_once("rsslib.php");
echo RSS_Display("http://www.xul.fr/rss.xml", 15);
? >

*/

$RSS_Content = array();

function RSS_Tags($item, $type)
{
    $y = array();
    $tnl = $item->getElementsByTagName("title");
    $tnl = $tnl->item(0);
    $title = $tnl->firstChild->textContent;

    $tnl = $item->getElementsByTagName("link");
    $tnl = $tnl->item(0);
    $link = $tnl->firstChild->textContent;

    $tnl = $item->getElementsByTagName("pubDate");
    $tnl = $tnl->item(0);
    $date = $tnl->firstChild->textContent;      

    $tnl = $item->getElementsByTagName("description");
    $tnl = $tnl->item(0);
    $description = $tnl->firstChild->textContent;

    $y["title"] = $title;
    $y["link"] = $link;
    $y["date"] = $date;     
    $y["description"] = $description;
    $y["type"] = $type;

    return $y;
}


function RSS_Channel($channel)
{
global $RSS_Content;

$items = $channel->getElementsByTagName("item");

// Processing channel

$y = RSS_Tags($channel, 0);     // get description of channel, type 0
array_push($RSS_Content, $y);

// Processing articles

foreach($items as $item)
{
    $y = RSS_Tags($item, 1);    // get description of article, type 1
    array_push($RSS_Content, $y);
}
}

function RSS_Retrieve($url)
{
global $RSS_Content;

$doc  = new DOMDocument();
$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
     RSS_Channel($channel);
}

}


function RSS_RetrieveLinks($url)
{
global $RSS_Content;

$doc  = new DOMDocument();
$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
    $items = $channel->getElementsByTagName("item");
    foreach($items as $item)
    {
        $y = RSS_Tags($item, 1);    // get description of article, type 1
        array_push($RSS_Content, $y);
    }

}

}


function RSS_Links($url, $size = 15)
{
global $RSS_Content;

$page = "<ul>";

RSS_RetrieveLinks($url);
if($size > 0)
    $recents = array_slice($RSS_Content, 0, $size + 1);



foreach($recents as $article)
{
    $type = $article["type"];
    if($type == 0) continue;
    $title = $article["title"];
    $link = $article["link"];
    $page .= "<li><a href=\"$link\">$title</a></li>\n";         
}

$page .="</ul>\n";

return $page;

}



function RSS_Display($url, $size = 18, $site = 0, $withdate = 0)
{
global $RSS_Content;

$opened = false;
$page = "";
$site = (intval($site) == 0) ? 1 : 0;

RSS_Retrieve($url);
if($size > 0)
    $recents = array_slice($RSS_Content, $site, $size + 1 - $site);

foreach($recents as $article)
{
    $type = $article["type"];
    if($type == 0)
    {
        if($opened == true)
        {
            $page .="</ul>\n";
            $opened = false;
        }
        $page .="<b>";
    }
    else
    {
        if($opened == false) 
        {
            $page .= "<ul>\n";
            $opened = true;
        }
    }
    $title = $article["title"];
    $link = $article["link"];
    $page .= "<li><a href=\"$link\">$title</a>";
    if($withdate)

    { 
  $date = $article["date"];
  $page .=' <span class="rssdate">'.$date.'</span>';
}
    $description = $article["description"];
    if($description != false)
    {
        $page .= "<br><span class='rssdesc'>$description</span>";
    }
    $page .= "</li>\n";         

    if($type==0)
    {
        $page .="</b><br />";
    }

}

if($opened == true)
{   
    $page .="</ul>\n";
}
return $page."\n";

}


?>

1 个答案:

答案 0 :(得分:0)

您正在使用的xml文件似乎有问题。我通过用提到的值替换url来尝试使用另一个xml。 $url = "http://www.scriptol.com/rss.xml"; 奇怪的是,现在似乎也在使用旧的xml。