Meltdown
05-11-2008, 11:22 PM
<?
$xml = simplexml_load_file('http://news.google.com/news?hl=en&q=miley+cyrus&ie=UTF-8&output=rss&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar');
//print_r($xml);
echo "<hr>";
foreach ($xml as $status) {
$title = $status->entry->title;
$link = $status->entry->link;
$test = $status->title;
echo "$title";
echo "<br>$test (to see if the feed is even being read...and it is)";
echo "<br>Link: $link";
}
?>
What I want to do: pull the data from the feed so I can manipulate it how I want.
What's not working: I can pull the title of the feed from the feed but nothing else. Here is how I think the feel is structured:
<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xml:lang="en" xmlns="http://purl.org/atom/ns#">
<generator>NFE/1.0</generator>
<title>miley cyrus - Google News </title>
<link rel="alternate" type="text/html" href="http://news.google.com/news?hl=en&q=miley+cyrus&ie=UTF-8&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar.xml"/>
<tagline>miley cyrus - Google News </tagline>
<author>
<name>Google Inc.</name>
<email>news-feedback@google.com</email>
</author>
<copyright>&copy;2008 Google</copyright>
<modified>2008-05-11T18:53:50Z</modified>
<entry>
<title type="text/html" mode="escaped">blah</title>
<link rel="alternate" type="text/html" href="blahblahblah.com"/>
<id>tag:news.google.com,2005:cluster=482dc827</id>
<issued>2008-05-11T07:43:40Z</issued>
<modified>2008-05-11T07:43:40Z</modified>
<content type="text/html" mode="escaped"> and content here and so on and so forth.
I don't understand what's going on.
_Aerospace_Eng_
05-11-2008, 11:36 PM
You can always navigate to the feed directly and go to view source you know to see its structure.
Meltdown
05-11-2008, 11:37 PM
..that's how I got what I posted. But it still isn't working. So either I'm overlooking something very simple or I'm way off track.
_Aerospace_Eng_
05-11-2008, 11:47 PM
Thats not how the feed is structured. You got some of it right. This is what I saw when I went directly to the source of the feed.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<generator>NFE/1.0</generator>
<title>miley cyrus - Google News</title>
<link>http://news.google.com/news?hl=en&q=miley+cyrus&ie=UTF-8&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&copy;2008 Google</copyright>
<pubDate>Sun, 11 May 2008 22:33:56 GMT</pubDate>
<lastBuildDate>Sun, 11 May 2008 22:33:56 GMT</lastBuildDate>
<image>
<title>miley cyrus - Google News</title>
<url>http://news.google.com/intl/en_us/images/news_res.gif</url>
<link>http://news.google.com/</link>
</image>
<item>
<title>Meghan O&#39;Rourke: The real Miley Cyrus tragedy - Dallas Morning News</title>
<link>http://news.google.com/news/url?sa=T&ct=us/0-0&fd=R&url=http://www.dallasnews.com/sharedcontent/dws/dn/opinion/points/stories/DN-orourke_11edi.ART.State.Edition1.466dbb8.html&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzeU9 bfFhiDNMTGxXRC8leoETE8rIA</link>
<guid isPermaLink="false">tag:news.google.com,2005:cluster=482dc827</guid>
<pubDate>Sun, 11 May 2008 07:43:40 GMT</pubDate>
<description><table border=0 width= valign=top cellpadding=2 cellspacing=7><tr><td width=80 align=center valign=top><font style="font-size:85%;font-family:arial,sans-serif"><a href="http://news.google.com/news/url?sa=T&ct=us/0i-0&fd=R&url=http://www.katu.com/news/entertainment/18561809.html&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzdcXZhepHFsQ-1JBh_kHQ8d4-RqRw"><img src=http://news.google.com/news?imgefp=gpju25FOW2EJ&imgurl=media.katu.com/images/080504_miley_cyrus.jpg width=80 height=60 alt="" border=1><br><font size=-2>KATU</font></a></font></td><td valign=top class=j><font style="font-size:85%;font-family:arial,sans-serif"><br><div style="padding-top:0.8em;"><img alt="" height="1" width="1"></div><div class=lh><a href="http://news.google.com/news/url?sa=T&ct=us/0-0&fd=R&url=http://www.dallasnews.com/sharedcontent/dws/dn/opinion/points/stories/DN-orourke_11edi.ART.State.Edition1.466dbb8.html&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzeU9 bfFhiDNMTGxXRC8leoETE8rIA">Meghan O&#39;Rourke: The real <b>Miley Cyrus</b> tragedy</a><br><font size=-1><font color=#6f6f6f>Dallas Morning News,&nbsp;TX&nbsp;-</font> <nobr>14 hours ago</nobr></font><br><font size=-1>Call me insensitive, but I didn&#39;t think that the supposedly &quot;racy&quot; photo of &#39;tween star <b>Miley Cyrus</b> holding a bedsheet around her bare torso was as outré as <b>...</b></font><br><font size=-1><a href="http://news.google.com/news/url?sa=T&ct=us/0-1&fd=R&url=http://www.eonline.com/uberblog/marc_malkin/b136171_miley_cyrus_new_singing_partner.html&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzcZx1-RaGz38fSS9faB8ItmCcyA6A"><b>Miley Cyrus</b>&#39; New Singing Partner</a> <font size=-1 color=#6f6f6f><nobr>E! Online</nobr></font></font><br><font size=-1><a href="http://news.google.com/news/url?sa=T&ct=us/0-2&fd=R&url=http://www.celebrity-gossip.net/celebrities/hollywood/miley-cyrus-new-singing-partner-204685/&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzeuNLcYNO4hKZsTLggGlq9RcVL0SA"><b>Miley Cyrus</b>: New Singing Partner?</a> <font size=-1 color=#6f6f6f><nobr>The Gossip Girls</nobr></font></font><br><font size=-1><a href="http://news.google.com/news/url?sa=T&ct=us/0-3&fd=R&url=http://justjared.buzznet.com/2008/05/10/miley-cyrus-john-travolta/&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzdVj9AGK12BK2Xp_ux1ib7TCo3VGA"><b>Miley Cyrus</b> &amp; John Travolta Duet in the Works?</a> <font size=-1 color=#6f6f6f><nobr>Just Jared</nobr></font></font><br><font size=-1 class=p><a href="http://news.google.com/news/url?sa=T&ct=us/0-4&fd=R&url=http://www.theglobeandmail.com/servlet/story/RTGAM.20080509.wdiary0510/BNStory/SpecialEvents2&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzeTfvWn6fjrjYf_wFjUwYTwom2Zlw"><nob r>Globe and Mail</nobr></a>&nbsp;- <a href="http://news.google.com/news/url?sa=T&ct=us/0-5&fd=R&url=http://www.pr-inside.com/cyrus-dismisses-scandal-over-racy-myspace-r581899.htm&cid=1210959911&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzcYwohRciT257jQHRX8mKh5ImiT4Q"><nobr>P R-Inside.com (Pressemitteilung)</nobr></a></font><br/><font class=p size=-1><a class=p href=http://news.google.com/news?hl=en&ie=UTF-8&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar&ncl=1210959911><nobr>all 434 news articles</nobr></a></font></div></font></td></tr></table></description>
</item>
<item>
<title>Hugh Hefner wants Miley Cyrus for Playboy. - Fashion.ie</title>
<link>http://news.google.com/news/url?sa=T&ct=us/1-0&fd=R&url=http://www.fashion.ie/aggregator/gossip/73989-hugh-hefner-wants-miley-cyrus-playboy&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzeDgDVxxAGB5YGX7-RJaF7DZ35-mA</link>
<guid isPermaLink="false">tag:news.google.com,2005:cluster=48353f27</guid>
<pubDate>Sun, 11 May 2008 17:09:49 GMT</pubDate>
<description><table border=0 width= valign=top cellpadding=2 cellspacing=7><tr><td width=80 align=center valign=top><font style="font-size:85%;font-family:arial,sans-serif"><a href="http://news.google.com/news/url?sa=T&ct=us/1i-0&fd=R&url=http://thecelebritytruth.com/miley-cyrus-apologizes-for-racy-photos/001485&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzfiZlF656MeYp9yc4ckkDzkZyMk8w"><img src=http://news.google.com/news?imgefp=hG1W7EbOKHMJ&imgurl=thecelebritytruth.com/assets/Uploads/Miley-Cyrus-Disney-Bob-DAmico.jpg width=80 height=67 alt="" border=1><br><font size=-2>The Celebrity Truth</font></a></font></td><td valign=top class=j><font style="font-size:85%;font-family:arial,sans-serif"><br><div style="padding-top:0.8em;"><img alt="" height="1" width="1"></div><div class=lh><a href="http://news.google.com/news/url?sa=T&ct=us/1-0&fd=R&url=http://www.fashion.ie/aggregator/gossip/73989-hugh-hefner-wants-miley-cyrus-playboy&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzeDgDVxxAGB5YGX7-RJaF7DZ35-mA">Hugh Hefner wants <b>Miley Cyrus</b> for Playboy.</a><br><font size=-1><font color=#6f6f6f>Fashion.ie,&nbsp;Ireland&nbsp;-</font> <nobr>5 hours ago</nobr></font><br><font size=-1>Hugh Hefner isn’t shy in wanting to tap <b>Miley Cyrus</b> for Playboy. Lets face it, she probably could do worse will do worse considering the pace she is on. <b>...</b></font><br><font size=-1><a href="http://news.google.com/news/url?sa=T&ct=us/1-1&fd=R&url=http://fametastic.co.uk/archive/20080511/11280/hugh-hefner-offers-miley-cyrus-a-playboy-shoot-once-she-turns-18/&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzevCGSDEqdnqPwIRc7k3AK4f7QfmA">Hugh Hefner offers <b>Miley Cyrus</b> a Playboy shoot - once she turns 18</a> <font size=-1 color=#6f6f6f><nobr>Fametastic</nobr></font></font><br><font size=-1><a href="http://news.google.com/news/url?sa=T&ct=us/1-2&fd=R&url=http://sundaygazettemail.com/News/200805090407&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzdWp1guQGtjiOkwm-KKAudse7F2hQ"><b>Miley Cyrus</b> reader response</a> <font size=-1 color=#6f6f6f><nobr>Charleston Gazette</nobr></font></font><br><font size=-1><a href="http://news.google.com/news/url?sa=T&ct=us/1-3&fd=R&url=http://blogs.reuters.com/fanfare/2008/05/09/hefner-wants-miley-cyrus-for-playboy-when-shes-legal/&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzd6Cfl6h16AZHZxiKL2fMeWZlH4qg">Hefner wants <b>Miley Cyrus</b> for Playboy - when she’s legal!</a> <font size=-1 color=#6f6f6f><nobr>Reuters UK</nobr></font></font><br><font size=-1 class=p><a href="http://news.google.com/news/url?sa=T&ct=us/1-4&fd=R&url=http://www.efluxmedia.com/news_Hefner_Wants_Miley_Cyrus_in_Playboy_17415.html&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFr qEzfqWpsr_Zj8lEllX0VJv-r04uzJBA"><nobr>eFluxMedia</nobr></a>&nbsp;- <a href="http://news.google.com/news/url?sa=T&ct=us/1-5&fd=R&url=http://www.nationalledger.com/artman/publish/article_272620483.shtml&cid=1211449127&ei=VHQnSKXhH4_w8AS8haiTAw&usg=AFrqEzcDWsO87MXDnZDJiP7lH-UNllMssA"><nobr>National Ledger</nobr></a></font><br/><font class=p size=-1><a class=p href=http://news.google.com/news?hl=en&ie=UTF-8&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar&ncl=1211449127><nobr>all 64 news articles</nobr></a></font></div></font></td></tr></table></description>
</item>
</channel>
</rss>
Meltdown
05-11-2008, 11:55 PM
ahh. How embarrassing. I must've been half asleep when I copied fro the feed source (otherwise, I don't know how I could've made such a mistake)
Anyway, so this thread isn't a complete waste, I'll post an updated, working version of my original code:
<?
$xml = simplexml_load_file('http://news.google.com/news?hl=en&q=miley+cyrus&ie=UTF-8&output=rss&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar');
foreach ($xml as $status) {
$title = $status->item->title;
$link = $status->item->link;
echo "$title<br>$link";
}
?>
Nates
06-13-2008, 10:11 PM
Does anyone know what would need to be added to show the latest 10 headlines.
I have this code working but its only shows 1 link
<?
$xml = simplexml_load_file('http://news.google.com/news?geo=90210&output=rss&ned=:ePkh8BM9EwLbocwl5pRallqUU6ngkZmTU6yj4OyooxAa7OjEamlgZGjg8X6aDsQNilwivvlFRZnFZUB1qToKYSFQdQamZma GHp-71ODOzIO4lUWIKTVHiAHiZjCVC3PwLzag1C821pz85MQcAA4IIOk');
foreach ($xml as $status) {
$link = $status->item->link;
$description = $status->item->description;
echo "$description <br> ";
}
?>
Thanks for any feedback
Nate
Meltdown
06-13-2008, 10:28 PM
$xml = simplexml_load_file('');
print_r($xml);
format as desired.
Nates
06-13-2008, 10:43 PM
Meltdown,
Thanks for the quick reply.
Tried this:
<?
$xml = simplexml_load_file('http://news.google.com/news?geo=90210&output=rss&ned=:ePkh8BM9EwLbocwl5pRallqUU6ngkZmTU6yj4OyooxAa7OjEamlgZGjg8X6aDsQNilwiv vlFRZnFZUB1qToKYSFQdQamZmaGHp-71ODOzIO4lUWIKTVHiAHiZjCVC3PwLzag1C821pz85MQcAA4IIOk');
print_r($xml);
foreach ($xml as $status) {
$link = $status->item->link;
$description = $status->item->description;
echo "$description <br> ";
}
?>
--------------
and it does display 10 results but also getting errors like below
) [3] => SimpleXMLElement Object ( [title] => SAG deal in June? Don't count on it - Hollywood Reporter [link] => http://news.google.com/news/url?sa=T&ct=us/3-0&fd=R&url=http://hollywoodreporter.com/hr/content_display/news/e3id5f52df31901946c211cc22eebb40f92%3Fimw%3DY&cid=1221923963&ei=vOlSSKuaMp-q9gSp06z-Cw&usg=AFQjCNGgcU9C5EspYSOGjS-i2csstYUHJw [guid] => tag:news.google.com,2005:cluster=48d5147b [pubDate] => Fri, 13 Jun 2008 05:32:17 GMT [description] =>
Meltdown
06-13-2008, 11:40 PM
that's not error.
that's raw.
like i said, you'll need to do your own formatting to tidy things up.
look it up:
http://php.net/simple_xml_loadfile
Nates
06-14-2008, 01:01 AM
Yea, thanks for the link...I was able to figure it out.