Solved

RSS reader won't work on my php5

Posted on 2009-04-10
12
306 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

708 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

15 Experts available now in Live!

Get 1:1 Help Now