RSS Reader in PHP

Here’s the bit of code I grabbed from PHP-Nuke with some modifications to display headlines from an RSS feed:

function headlines($url) {
	$fp = @fopen($url, "r");
	if ($fp) {
	    $string = "";
	    while(!feof($fp)) {
	    	$string .= chop(fgets($fp,300));
	    }
	    fclose($fp);
	    $items = explode("</item>",$string);
	    $content = "";
	    for ($i=0;$i<10;$i++) {
		$link = ereg_replace(".*<link>","",$items[$i]);
		$link = ereg_replace("</link>.*","",$link);
		$title = ereg_replace(".*<title>","",$items[$i]);
		$title = stripslashes(ereg_replace("</title>.*","",$title));
		if (strcmp($link,$title) AND $items[$i] != "") {
		    $content .= "<strong><big>·</big></strong><a href="$link" target="new">$title</a><br>\n";
		}
	    }
	}
	return $content;
}

Comments are closed.