Re: array issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Clare Media wrote:
> 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;
> 
>                                 
Count the elements in $this->data = @file_get_contents( $file );
If more then one then loop else use the code below:

ex:
if( count( $this->data = @file_get_contents( $file ) < 1 ) ) {
 foreach( $this->data as $key => $value ) {
  // show your titles etc.
 }
} else {
> 
>                                 // 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));
> 
>                 }
> 
> 


- --
Jason Gerfen

"I practice my religion
 while stepping on your
 toes..."
~The Ditty Bops
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHTGMM5vk8bwKVAaIRAhAjAJ9FklveFH1PORVl0HC9nCb+klgcUACeOren
RgXSIP0bl/bt9rI6g9a/6Uk=
=y9XX
-----END PGP SIGNATURE-----

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux