Jump to content

Recommended Posts

i followed the guide on this site for the rss tutorial.

i altered it to what i wanted but i can not get it to loop. it will only display the first line.

the tutorial says to use echo <<<EOF but they caused the script to not work.

 

any help would be gratefull.

 

<?php
$xml = new SimpleXMLElement('http://api.wot-blackdeath.ru/wot-news/eu/wot-news.xml', null, true);

echo "<table border='1'>" ;	  

foreach($xml as $data){
// loop through our xml	   
?>			   
<tr><td> <?php echo $data->title ?></td></tr>			  
<tr><td> <?php echo $data->description ?></td></tr>			  
<tr><td> <?php echo $data->link ?></td></tr>		  
<tr><td> <?php echo $data->pubDate ?></td></tr>					 
<?php
}
echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/
Share on other sites

The xml looks like it could contain any number of <channel> entries. Each of these channels has its own title, description etc. as well as any number of <item> entries which also have their own title, description etc.

 

So, going by the code you have so far, it might read better as:

 

<?php foreach ($xml as $channel) : ?>

 

Then you could access the CHANNEL info like this:

 

<?php echo $channel->title; ?>
<?php echo $channel->description; ?>
etc...

 

You could then cycle through each $channel's <item> entries:

 

<?php foreach ($channel->item as $item) : ?>

 

After which you could access the ITEM info like this:

 

<?php echo $item->title; ?>
<?php echo $item->description; ?>
etc...

 

Hope that clears things up a little.

Link to comment
https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409677
Share on other sites

i carnt get my head round this lol.

 

the xml im reading is laid out like this

 

<channel>
 <item>
	 <title>data</title>
	 <description>data</description>
	 <link>data</link>
	 <pubDate>data</pubDate>
	 <guid>data</guid>
 </item>


 <item>
	 <title>data</title>
	 <description>data</description>
	 <link>data</link>
	 <pubDate>data</pubDate>
	 <guid>data</guid>
</item>
<channel>

 

using following code i get the php to loop the correct amount of times ( 8) but the echo'd value is "item"

<?php
$xml = new SimpleXMLElement('http://api.wot-blackdeath.ru/wot-news/eu/wot-news.xml', null, true);
echo "<table border='1'>" ;	
foreach($xml->channel->item as $data => $value){

?>			
<tr><td>1</td><td><b> <?php echo $data ?></b></td></tr>			
<tr><td>2</td><td> <?php echo $data ?></td></tr>			
<tr><td>3</td><td> <?php echo $data ?></td></tr>		
<tr><td>4</td><td> <?php echo $data ?></td></tr>					
<tr><td>5</td><td> <?php echo $data ?></td></tr>
<?php
}
echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/273937-php-rss-tutorial/#findComment-1409685
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.