Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
NDD Camp 2024

Fresh TOPICAL Content for Your site.

Status
Not open for further replies.

namestrands

The Bishop
Legacy Exclusive Member
Joined
Jan 16, 2005
Messages
3,924
Reaction score
6
Need to fill up some space on your site with relative content.. ?
PHP:
<?php

$keyword = urlencode("YOUR KEYWORDS");

set_time_limit(0);

$file = "http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=$keyword&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>");
	}
}

?>
 

jdk

DNF Addict
Legacy Exclusive Member
Joined
Jul 23, 2004
Messages
6,347
Reaction score
19
Very nice. Thank you.
 

elearningtoys

Platinum Lifetime Member
Legacy Exclusive Member
Joined
Jan 9, 2005
Messages
243
Reaction score
0
This was JUST what I was looking for! Thank you so much!
 

dudeinva

Platinum Lifetime Member
Legacy Exclusive Member
Joined
Jul 20, 2004
Messages
222
Reaction score
0
I'm a php noice as well. I'd like to see how it looks. Can you point us to a site that's using it?
 

fab

Level 9
Legacy Exclusive Member
Joined
Dec 11, 2004
Messages
3,554
Reaction score
1

cinran

DNF Member
Legacy Exclusive Member
Joined
Apr 22, 2004
Messages
238
Reaction score
0
Just add a file named go.php in the same directory and include the following code in the go.php file:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:".$HTTP_GET_VARS['url']."");
exit;
?>


----------------------------------------
Example: http://www.lowintro.com/news.php
 

namestrands

The Bishop
Legacy Exclusive Member
Joined
Jan 16, 2005
Messages
3,924
Reaction score
6
you do not need the 301 redirect as this will cause you untold search ranking problems if you have several on the same page.

Simply create a new file called go.php and upload it to the root directory.

then add the folowing code.

PHP:
<?
$links = $_GET['url'];
header("Location: $links");
exit();
?>
 

diverge

DNF Addict
Legacy Exclusive Member
Joined
Apr 18, 2003
Messages
1,443
Reaction score
0
Woot! What a great script. I am going to use this one. Did you do this one yourself, or find it somewhere? Either way, great post!
 

fab

Level 9
Legacy Exclusive Member
Joined
Dec 11, 2004
Messages
3,554
Reaction score
1
You should read through this thread, especially Cinran's post -
Just add a file named go.php in the same directory and include the following code in the go.php file:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:".$HTTP_GET_VARS['url']."");
exit;
?>
I have an example above as well.
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
MariaBuy

Our Mods' Businesses

URL Shortener
UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom