Solved

RSS reader won't work on my php5

Posted on 2009-04-10
12
313 Views
Last Modified: 2012-05-06
guys here is my code and I've tried some other scripts online and same thing I can't get it to work please let me know if you see anything wrong with this.

Here is my phpinfo - http://128.121.66.235/phpinfo.php
script url - http://marcioarantes.securesites.net/temp/
<?
 
 
 $xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");
 
 
 
 
$xmlDoc = new DOMDocument();
 
$xmlDoc->load($xml);
 
echo $xmlDoc;
 
 
//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
//output elements from "<channel>"
echo("<p><a href='" . $channel_link
 . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");
//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++)
 {
 $item_title=$x->item($i)->getElementsByTagName('title')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_link=$x->item($i)->getElementsByTagName('link')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_desc=$x->item($i)->getElementsByTagName('description')
 ->item(0)->childNodes->item(0)->nodeValue;
 echo ("<p><a href='" . $item_link
 . "'>" . $item_title . "</a>");
 echo ("<br />");
 echo ($item_desc . "</p>");
 }
?>

Open in new window

0
Comment
Question by:n0cud06
  • 7
  • 5
12 Comments
 
LVL 10

Expert Comment

by:Phatzer
ID: 24118396
I can't see much wrong, you need to show us some errors if possible... Although, this looks suspicious:

$xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");

Should it just not be:

$xml="http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml";
0
 

Author Comment

by:n0cud06
ID: 24118814
yes you're right I'm sorry I was testing it, I think the the problem is with the object $xmlDoc = new DOMDocument();

can someone try this please



<?
//get the q parameter from URL
//$q=$_GET["q"];

 $xml= "http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml";

 
 //xml assigned
 //echo $xml;
 
 
$xmlDoc = new DOMDocument();

$xmlDoc->load($xml);

echo $xmlDoc;


//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
//output elements from "<channel>"
echo("<p><a href='" . $channel_link
 . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");
//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++)
 {
 $item_title=$x->item($i)->getElementsByTagName('title')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_link=$x->item($i)->getElementsByTagName('link')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_desc=$x->item($i)->getElementsByTagName('description')
 ->item(0)->childNodes->item(0)->nodeValue;
 echo ("<p><a href='" . $item_link
 . "'>" . $item_title . "</a>");
 echo ("<br />");
 echo ($item_desc . "</p>");
 }
?>
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24118832
Just quickly, I've not used the DOMDocument class, but I think you need the PHP XML extension enabled to use it if you've not already done that.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Phatzer
ID: 24118845
I have an error on line 16 by the way... you need to comment out 'echo $xmlDoc;' as you're trying to output an object as a string.

If you needed to do that for whatever reason, I think you'd need to do print_r($xmlDoc);
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24118858
This works for me...
<?
//get the q parameter from URL
//$q=$_GET["q"];
 
 $xml= "http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml";
 
 
 //xml assigned
 //echo $xml;
 
 
$xmlDoc = new DOMDocument();
 
$xmlDoc->load($xml);
 
//print_r($xmlDoc);
 
 
//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
//output elements from "<channel>"
echo("<p><a href='" . $channel_link
 . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");
//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++)
 {
 $item_title=$x->item($i)->getElementsByTagName('title')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_link=$x->item($i)->getElementsByTagName('link')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_desc=$x->item($i)->getElementsByTagName('description')
 ->item(0)->childNodes->item(0)->nodeValue;
 echo ("<p><a href='" . $item_link
 . "'>" . $item_title . "</a>");
 echo ("<br />");
 echo ($item_desc . "</p>");
 }
?>

Open in new window

0
 

Author Comment

by:n0cud06
ID: 24118882
Phatzer, how do I enable that? I have a dedicated server so I can make changes to php.ini http://128.121.66.235/phpinfo.php
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24118888
You might not need to, I didn't have to... Have you tried with the changes I made?
0
 

Author Comment

by:n0cud06
ID: 24118935
yes I did here is the error I get with your code

Fatal error: Class 'DOMDocument' not found in /usr/local/apache2/htdocs/temp/getrss.php on line 12
0
 
LVL 10

Accepted Solution

by:
Phatzer earned 500 total points
ID: 24118959
I'm not sure on the installation process with FreeBSD, but does this help?

http://www.freshports.org/textproc/php5-xml/
0
 

Author Comment

by:n0cud06
ID: 24119076
uhmm I installed the ext. and disable zend.ze1_compatibility_mode already but still getting this

Fatal error: Cannot clone object of class DOMDocument due to 'zend.ze1_compatibility_mode'
0
 

Author Closing Comment

by:n0cud06
ID: 31569007
I got it thank you so much for your time and help :)
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24119141
Hmm I'm not sure how much more I can help on that one, try restarting apache. If that doesn't work, I'd open a new question for it :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question