Recommended Posts

I'm having trouble figuring out what it is. I tried turning on strict error reporting, and it told me one thing that was legal in the language, but not preferred. I changed this, and maybe it fixed the problem.

Try this instead:

	<?
	error_reporting(2048);
	$domdoc = new DomDocument;
	$domdoc->load('http://blog.mynimal.net/?feed=rss2');
	$xpath = new DOMXPath($domdoc);
	$titles = $xpath->query('/*/channel/item/title');
	for ($i = 0; $i < $titles->length; $i++)
	{
  echo $titles->item($i)->nodeValue;
  echo '<br>';
	}
	?>

Edited by benjeeeboy

Will this code work on PHP4? I was thinking that the 'try { } catch { }' statments was a new thing in PHP5. I might be getting some hosting in the next few weeks and wanted to use this but they only use PHP4 where I'll be getting hosting.

Cheers,

-Techy

I have absolutely no idea if it will work on PHP4. In my newer version that I am working on now, i will try to not use exceptions, so it may be compatible. I am just re-learning php now, so it may take a bit to get everything working perfectly but i will add php4 compatibility to my todo list.

I added a bunch to the test code (please post the results). Maybe this will give more insight into whats wrong so i can fix this and get and moving on the new version.

<?
	$domdoc = new DomDocument;
	$domdoc->load('http://blog.mynimal.net/?feed=rss2');
	$xpath = new DOMXPath($domdoc);
	$titles = $xpath->query('/*/channel/item/title');
	echo "Number of entries: ";
	echo $titles->length;
	echo "<br>";
	for ($i = 0; $i < $titles->length; $i++)
	{
  $itemnode = $titles->item($i);
  echo $itemnode->nodeName;
  echo ": ";
  echo $itemnode->nodeValue;
  echo '<br>';
	}
	echo "<p>";
	echo "other way:";
	echo "<br>";
	$itemlist = $domdoc->getElementsByTagName('item');
	echo "num items: ";
	echo $itemlist->length;
	echo "<br>";
	for ($j=0;$j<$itemlist->length;$j++)
	{
  $item = $itemlist->item($j);
  $itemtitles = $item->childNodes;
  for ($k=0;$k<$itemtitles->length;$k++)
  {
  	if ($itemtitles->item($k)->nodeName=='title')
  	{
    echo $itemtitles->item($k)->nodeValue;
    echo '<br>';
  	}
  }
	}
?>

Thank you for helping me help you.

Edited by benjeeeboy
I added a bunch to the test code (please post the results).  Maybe this will give more insight into whats wrong so i can fix this and get and moving on the new version.

Thank you for helping me help you.

586283921[/snapback]

Same error as before. :(

Parse error: parse error, unexpected T_OBJECT_OPERATOR in /www/g/gfxutopianet/htdocs/rss/rss-feed.php on line 30

Line 30:

  	if ($itemtitles->item($k)->nodeName=='title')

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.