Solved

RSS reader won't work on my php5

Posted on 2009-04-10
12
307 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

932 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

10 Experts available now in Live!

Get 1:1 Help Now