I have an RSS feed set up using XML on the website I've developed for Pantheon Arts Unlimited. I'm still fairly new to PHP and MySQL, so I find myself often jumping to various forums looking for answers for what are usually fairly obvious questions.

My newest problem, however, I've yet to find an answer without it being "WordPress." I want to develop the site at least 80% myself and not rely on third-party sources for such a large undertaking. I like having strict control over my code.

Anyways. I have an RSS feed running off XML, and I'm parsing it alright on the News page. I want to use $_GET to grab the news.php?post=postNumber bit from the URL and compare it to the GUID in the XML.

Essentially, take the GUID in the XML, compare it to the $_GET string, and it they match, only parse that item. If they don't match, keep looking until they do. If none of them do, then just say screw it and 404 or something. I really don't care about that part as much.

Here's the XML parser code:

<?
	$GLOBALS['titletag'] = false;
	$GLOBALS['linktag']  = false;
	$GLOBALS['descriptiontag'] = false;
	$GLOBALS['pubDatetag'] = false;
	$GLOBALS['authortag'] = false;
	$GLOBALS['categorytag'] = false;
	$GLOBALS['guidtag'] = false;
	$GLOBALS['thetitletxt'] = null;
	$GLOBALS['thelinktxt'] = null;
	$GLOBALS['thedesctxt'] = null;
	$GLOBALS['thepubDatetxt'] = null;
	$GLOBALS['theauthortxt'] = null;
	$GLOBALS['thecategorytxt'] = null;
	$GLOBALS['theguidtxt'] = null;

	function startTag($parser, $tagName, $attrs)
	{
		switch($tagName)
		{
			case 'TITLE':
				$GLOBALS['titletag'] = true;
				break;
			case 'LINK':
				$GLOBALS['linktag'] = true;
				break;
			case 'DESCRIPTION':
				$GLOBALS['descriptiontag'] = true;
				break;
			case 'PUBDATE':
				$GLOBALS['pubDatetag'] = true;
				break;
			case 'AUTHOR':
				$GLOBALS['authortag'] = true;
				break;
			case 'CATEGORY':
				$GLOBALS['categorytag'] = true;
				break;
			case 'GUID':
				$GLOBALS['guidtag'] = true;
				break;
		}
	}

	function endTag($parser, $tagName)
	{
		switch($tagName)
		{
			case 'TITLE':
				echo "<p><b>" . $GLOBALS['thetitletxt'] . "</b><br>";
				$GLOBALS['titletag'] = false;
				$GLOBALS['thetitletxt'] = "";
				break;
			case 'LINK':
				echo "&nbsp;&nbsp;&nbsp;Link: <a href=\"". $GLOBALS['thelinktxt'] . "\">" . $GLOBALS['thelinktxt'] . "</a><br>";
				$GLOBALS['linktag'] = false;
				$GLOBALS['thelinktxt'] = "";
				break;
			case 'DESCRIPTION':
				echo "&nbsp;&nbsp;&nbsp;" . $GLOBALS['thedesctxt'] . "<br>";
				$GLOBALS['descriptiontag'] = false;
				$GLOBALS['thedesctxt'] = "";
				break;
			case 'PUBDATE':
				echo "&nbsp;&nbsp;&nbsp;Published <i>" . $GLOBALS['thepubDatetxt'] . "</i><br>";
				$GLOBALS['pubDatetag'] = false;
				$GLOBALS['thepubDatetxt'] = "";
				break;
			case 'AUTHOR':
				echo "&nbsp;&nbsp;&nbsp;By: <i>" . $GLOBALS['theauthortxt'] . "</i><br>";
				$GLOBALS['authortag'] = false;
				$GLOBALS['theauthortxt'] = "";
				break;
			case 'CATEGORY':
				echo "&nbsp;&nbsp;&nbsp;Category: <i>" . $GLOBALS['thecategorytxt'] . "</i><br>";
				$GLOBALS['categorytag'] = false;
				$GLOBALS['thecategorytxt'] = "";
				break;
			case 'GUID':
				echo '&nbsp;&nbsp;&nbsp;<a href="' . $GLOBALS['theguidtxt'] . '">Article Page</a></p>';
		}
	}

	function txtTag($parser, $text)
	{
		if($GLOBALS['titletag'] == true)
		{
			$GLOBALS['thetitletxt'] .= htmlspecialchars(trim($text));
		} else if($GLOBALS['linktag'] == true)
		{
			$GLOBALS['thelinktxt']  .= trim($text);
		} else if($GLOBALS['descriptiontag'] == true)
		{
			$GLOBALS['thedesctxt'] .= htmlspecialchars(trim($text));
		} else if($GLOBALS['pubDatetag'] == true)
		{
			$GLOBALS['thepubDatetxt'] .= trim($text);
		} else if($GLOBALS['authortag'] == true)
		{
			$GLOBALS['theauthortxt'] .= trim($text);
		} else if($GLOBALS['categorytag'] == true)
		{
			$GLOBALS['thecategorytxt'] .= trim($text);
		} else if($GLOBALS['guidtag'] == true)
		{
			$GLOBALS['theguidtxt'] .= trim($text);
		}
	}

	function parsefile($RSSfile)
	{
		// Create an xml parser
		$xmlParser = xml_parser_create();
		
		// Set up element handler
		
		xml_set_element_handler($xmlParser, "startTag", "endTag");
		// Set up character handler
		
		xml_set_character_data_handler($xmlParser, "TxtTag");
		// Open connection to RSS XML file for parsing.
		
		$fp = fopen($RSSfile,"r") or die("Cannot read RSS data file.");
		// Parse XML data from RSS file.
		
		while($data = fread($fp, 4096))
		{
			xml_parse($xmlParser, $data, feof($fp));
		}
		
		// Close file open handler
		fclose($fp);
		
		// Free xml parser from memory
		xml_parser_free($xmlParser);
	}
?>

And no, I don't know any other "advanced" codes like Javascript. Just PHP and HTML/CSS.

I've decided to use PHP and MySQL to synthesis the XML.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.