Jump to content

[SOLVED] news feed


Ninjakreborn

Recommended Posts

Sorry

* News Aggregator.

However no, I don't know too much about what they are.

I know a new's feed is an xml feed with new's, and an aggragator handles feed's.

I just need "something" that handles what I asked, or atleast a good new's feed that I can rely on.

I don't know exactly what is needed either, he just said he wanted hispanic news setup on his site, not sure what I am looking for, just looking. Any advice?

Link to comment
Share on other sites

??? First of all it's "news"... not "new's".

 

Secondly, it's going to be hard to find a feed in spanish since most international news is in english.

 

Third, handling a feed is really quite simple.

<div style="overflow:auto;height:100px;border:1px solid gray;background-color:white;padding:5px;font-size:10pt;" class="smalltext">
<?php
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";

function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
	$tag = $name;
} elseif ($name == "ITEM") {
	$insideitem = true;
}
}

function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == "ITEM") {
	printf("<dt><b><a href='%s'>%s</a></b></dt>",
		trim($link),htmlspecialchars(trim($title)));
	printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
	$title = "";
	$description = "";
	$link = "";
	$insideitem = false;
}
}

function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
	case "TITLE":
	$title .= $data;
	break;
	case "DESCRIPTION":
	$description .= $data;
	break;
	case "LINK":
	$link .= $data;
	break;
}
}
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://www.entrepreneur.com/feeds/marketing.rss","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
	or die(sprintf("XML error: %s at line %d",
		xml_error_string(xml_get_error_code($xml_parser)),
		xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>
</div>

 

Simply replace the link with the address to whatever feed you want to pull.

Link to comment
Share on other sites

Additionally "universal reports" doesn't make much sense unless that is somehow supposed to mean "international".  And you're never going to find a feed that is zipcode specific.  You'd have to get the feed from local news stations.

Link to comment
Share on other sites

The code you gave me is amazing.

 

THis is something I Fought with on another project that took me about 2 weeks and still didn't finish.

I was wondering,w hat about this code makes it work for any situation.

Can you reput the code (anyone) and comment it as best you can to help me fully understand the code, so I can understand it and study it some?

 

Thanks again for the help.

Link to comment
Share on other sites

What makes it work for any situation???  Possibly the fact that RSS feeds all use the same format and tags?

 

The code is really quite simple.  If you spend more than five minutes with it, I really think you'll be able to figure it out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.