Solved

RSS reader won't work on my php5

Posted on 2009-04-10
12
308 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now