![]() |
|
|
|
|||||||
| Home | Chat | Register | FAQ | Calendar | Mark Forums Read |
| General Development General Development |
|
|
Thread Tools | Display Modes |
|
||||
|
I have been looking to knock up a few more of my domains instead of parking them, and I remembered about a site I used to have a few years ago before selling it off to someone, which used an RSS parser / PHP script, that would pull content from Google news related to whatever keyword/s I wanted.
I thought I would try and use it for a few of my idns. However, I am having a few problems getting it to work in languages other than english. There are two files used - index.php and rss.inc Index.php ( Main page ) This contains the following code ... <?php include("rss.inc"); ?> ------------ Rss.inc ( Script that pulls the content from Google News ) Code:
<?php
set_time_limit(0);
$file = "http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=KEYWORD-WILL-GO-IN-HERE&output=rss";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}
function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
// output HTML
// print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
print ("\n<div class=\"itemtitle\"><a href=\"" . "go.php?url=" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
} else {
print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
}
print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); }
} else {
print ("<b>There are no articles in this feed.</b>");
}
}
?>
-- EDITED at member's request. -- Has anyone got an suggestions as to what I might be doing wrong, or any similar scripts/solutions, that I can use to grab content from Google news. Thanks for your time Alex
__________________
"She thinks I'm a nice guy. Women always think I'm nice. But women don't want nice. Why is nice bad? What kind of a sick society are we living in when nice is bad?" George Costanza Last edited by mj : 8th May 2008 at 15:55:13. |
|
||||
|
$keyword = "köln";
$encoded_keyword = urlencode($keyword); $file = "http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=$encoded_keyword&output=rss"; .
__________________
"The meaning of life is to live a life of meaning." |
|
||||
|
Mike
Thanks so much for that. I seems to be working great. Alex
__________________
"She thinks I'm a nice guy. Women always think I'm nice. But women don't want nice. Why is nice bad? What kind of a sick society are we living in when nice is bad?" George Costanza |
|
||||
|
Cool. Glad I could help.
.
__________________
"The meaning of life is to live a life of meaning." |
|
|||
|
Great script and thx to the mod from mj it works fine for Chinese as well.
I did change the news source to google.cn. Alexd, do you have sample sites where you use it which are revealable, I'm looking for ideas/inspiration on how to incorporate it.
__________________
علی.com/net | φαρμακα.com | комментарии.com | סקסי.com | 封筒.com | 不知道.com and many more |
|
||||
|
Do search engines seem to care either way? Are you caching the information so it can be indexed? Is caching 'allowed' or 'penalized' in any way?
My RSS feed seemed to have trouble running when IE7 came out. I put that on the backburner, but you have renewed my interest. |
|
|||
|
I am going to release this one to everyone very soon:
Keyword based + multiple feeds (compatible with 99% of the feeds) + ebay (keyword based also) + full utf-8 compatible. PM for demo. Last edited by Lidador : 24th May 2008 at 20:37:51. |
| Thread Tools | |
| Display Modes | |
|
|