Guys really in need of some assistance here.

I am reading an xml file and want to loop through the entire file and
display the information.

Unfortunately I am only showing 1 item. how can I go about showing all news
item?

I've tried array and loop however I am not versed with any of them.

Thanks in advance

 

 

eg.

-------------------------------------------------------------------------

                <item>

                                <title>title 1</title>

                                <description>Description 1</description>

                </item>

<item>

                                <title>title 2</title>

                                <description>Description 2</description>

                </item>

<item>

                                <title>title 3</title>

                                <description>Description 3</description>

                </item>

-------------------------------------------------------------------------

 

My current code

+++++++++++++++++++++++++++++++++

function getNews() 

                {

                                $file = NEWS_FILE.".xml";

                                if(!file_exists($file) || filemtime($file) <
time() - 43200) {

                                                $this->data =
@file_get_contents("http://feeds.mydomain.com/dailynews";);

                                                $fp = @fopen($file, 'w');

                                                @fwrite($fp, $this->data);

                                                @fclose($fd);

                                }

                                else $this->data =
@file_get_contents($file);

                                if(strlen($this->data) <= 0) return;

                                

                                // get the location

                                $attr = explode('<', $this->tag('item'));


                                $return['title'] = $attr[1];

                                $return['title'] = substr($return['title'],
6);

 

                                $return['description'] = $attr[7];

                                $return['description'] =
substr($return['description'], 2);

 

                                return $return;

                }

                

                function view_news()

                {

                                

                                $currentNews = newsfeed::getNews();

                                

                                $NEWS=
'<strong>'.$currentNews['title'].'</strong><br>'.$currentNews['description']
..'<br/>';

                                

                                return $NEWS;

                

                }

 

function tag($tag, $skip=0) 

                {

                                $start = -1;

                                for($i = 0; $i <= $skip; $i++)

                                                $start = strpos($this->data,
"<{$tag}", $start + 1);

                                if($start === false) return false;

                                $start += strlen($tag) + 1;

                                $end = strpos($this->data, "</{$tag}>",
$start);

                                if($end === false)

                                                $end = strpos($this->data,
'/>', $start);

                                return trim(substr($this->data, $start, $end
- $start));

                }

Reply via email to