Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RSS reader won't work on my php5

Posted on 2009-04-10
12
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

598 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