$feed=file_get_contents('URL'); $rss=new SimpleXmlElement($feed); foreach($rss->channel->item as $entry) { echo "<p><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></p>"; } PHP: I used a blog's rss feed address instead of the url in $feed,but it didn't work. why? i learn php recently,can anyone give me the meanings of the $rss->channel->item .thank you! PS:my php environment supports the file_get_contents()function.
$rss->channel->item relates to Class and Object. Read the manual for Classes and Object in php as php is Object-oriented programming language. If you are totally new to php and haven't learned any programming language before, don't bother this stuff right now. It just gives you headache .
first,thank you for yours answers.i have read the php's Class and Object.too disappointed and puzzled.now,i know that states a class,the format is and when refer a variable from a class,the format is $variablename=new classname, $variablename->variablename, from these,i found there is no channel in SimpleXmlElement. why ,who can explain these for me. 3Q!
If this is not working $feed=file_get_contents('URL'); Please try getting the contents using curl and parse the output using the SimpleXMLElement Thanks!!
magpierss.sourceforge.net require_once 'rss_fetch.inc'; $url = 'http://magpie.sf.net/samples/imc.1-0.rdf'; $rss = fetch_rss($url); echo "Site: ", $rss->channel['title'], "<br> "; foreach ($rss->items as $item ) { $title = $item[title]; $url = $item[link]; echo "<a href=$url>$title</a></li><br> "; } Code (markup):