Jump to content

Php rss and marquee problem !?


crepiuza

Recommended Posts

Hello everybody ,

i echo into a marquee one variable which is having value (item) of a rss feed which am parsing .

 

The problem is that into the marquee, is echoed finally, just the first item and not all the items of the feed !

 

So when am parsing a News rss feed, which is having par example 5 news, my marquee is showing just the first of those 5 :(

 

Why is this happening ?

 

Here is the code i use :

 

The marquee

<marquee behavior="scroll" scrollamount="5"><b><?php echo "<a href=$sigma2>$sealakefa</a></b></marquee>

 

The php/rss part

function readRSSFile($filename) {
        $data = implode('', file($filename));
        $parser = xml_parser_create();
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
        xml_parse_into_struct($parser, $data, $values, $tags);
        xml_parser_free($parser);

        foreach ($tags as $key => $val) {
                if ($key == 'item') {
                        $itemRanges = $val;
                        
                        for($i=0; $i<count($itemRanges); $i+=2) {
                                $offset = $itemRanges[$i] + 1;
                                $len = $itemRanges[$i + 1] - $offset;
                                $result[] = combineItem(array_slice($values, $offset, $len));
                        }
                }
        }
        return $result;
}

function combineItem($itemValues) {
        for ($i=0; $i<count($itemValues); $i++) {
                if(isset($itemValues[$i]['value'])) {
                        $item[$itemValues[$i]['tag']] = $itemValues[$i]['value'];
                }
        }
        return $item;
} 


$latest = readRSSFile("http://www.jamaicaobserver.com/rss/news/");

for($i=0; $i<count($latest); $i++) {
        $sigma = $latest[$i]['link'];
        $tauvf = $latest[$i]['title'];   
}

 

I want all the items of the feed to be shown into my marquee !

How to do that can you help me please ..? What's wrong ? :wtf:

 

Thanks in advance..

Link to comment
https://forums.phpfreaks.com/topic/215808-php-rss-and-marquee-problem/
Share on other sites

Not sure if this will show the result you want, but it should work:

<?php

function readRSSFile($filename) {

$xml = new SimpleXMLElement(file_get_contents($filename));

return $xml->channel;

}

$latest = readRSSFile("http://www.jamaicaobserver.com/rss/news/");

foreach($latest->item as $latest) {

$sigma = $latest->link;
$tauvf = $latest->title;

?>

<marquee behavior="scroll" scrollamount="5"><b><a href="<?php echo $sigma; ?>"><?php echo $tauvf; ?></a></b></marquee>

<?php
}
?>

 

Oh thank you very much phpeter, that works !

 

Just i face a litle trouble now,

cause, the marquee is horizontial and the news that we fecth are shown in the page vertical !

Each one downside of the other, in this way :

news no1

news no2

news no3

news no4

news no5

 

but i want these news to be shown horizontially and not as now vertical, like this :

 

news no1 news no2 ... ...news no5

 

How to fix that ..? :confused:

 

doh! I should have caught that before I posted. It's repeating marquees instead of putting all of the links into one. This should fix it:

<marquee behavior="scroll" scrollamount="5">

<?php

function readRSSFile($filename) {

$xml = new SimpleXMLElement(file_get_contents($filename));

return $xml->channel;

}

$latest = readRSSFile("http://www.jamaicaobserver.com/rss/news/");

foreach($latest->item as $latest) {

$sigma = $latest->link;
$tauvf = $latest->title;

?>

<b><a href="<?php echo $sigma; ?>"><?php echo $tauvf; ?></a></b>

<?php
}
?>

</marquee>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.