All pastes #265557 Raw Edit

Donno

public text v1 · immutable
·published 2006-12-03 11:33 UTC
rendered paste body
<?php
	$url = "http://darkdonno.wordpress.com/?feed=rss2";
	$initem = 0;
	global $whichtag;
	$whichtag = 0;
	
	if (! ($xmlparser = xml_parser_create()) )
	{
		die ("Cannot create parser");
	}
	function start_tag($parser, $name, $attribs) {
		//echo $name;
		if ($name == "ITEM")
		{
			echo "<!-- Start Item -->";
			$initem = 1;
			
		}
		
		else if ($name == "TITLE"){
			global $whichtag;
			$whichtag = 1;
		}
		else if ($name == "LINK"){
			global $whichtag;
			$whichtag = 2;
		}
		else if ($name == "DESCRIPTION"){
			global $whichtag;
			$whichtag = 3;
		}
    } 
	function end_tag($parser, $name) {
		if ($name == "ITEM")
		{
			echo "<!-- End Item -->";
			$initem = 0;
		}
		else if ($name == "TITLE") {
			global $whichtag;	
			$whichtag = 0;
		}
		else if ($name == "DESCRIPTION") {
			global $whichtag;	
			$whichtag = 0;
			echo "</div>";
		}
		else if ($name == "LINK") {
			global $whichtag;	
			$whichtag = 0;
		}	
	}
   function tag_contents($parser, $data) {
   		global $whichtag;
		if ($whichtag == 1)
		{ 
			echo '<div class="item-header"><a href="javascript:spin(' . "'xbmc'" . ')" id="xbmc">-</a><a href="javascript:spin(' . "'xbmc'". ')">' . $data ."</a></div>";
			echo '<div class="item-body" id="xbmc_body" style="visibility: visible;">';
		} else if ($whichtag == 2) {
			echo 'Link: <a href="' .$data . '"> Full Story Here</a><br />';
		}
		else if ($whichtag == 3) {
			echo $data;
		}
       //echo "Contents : ".$data."<br />";
    }
	$result = file_get_contents($url, false);
	
	xml_set_element_handler($xmlparser, "start_tag", "end_tag");
	xml_set_character_data_handler($xmlparser, "tag_contents"); 
	
	$data=eregi_replace(">"."[[:space:]]+"."< ",">< ",$result);
	if (!xml_parse($xmlparser, $data)) {
		$reason = xml_error_string(xml_get_error_code($xmlparser));
		$reason .= xml_get_current_line_number($xmlparser);
		die($reason);
		}
	xml_parser_free($xmlparser); 
?>