Industry News

Charlotte Marketing Agency

Charlotte Marketing Agency



%s

“,
trim($link),(trim($title)));

//Description (with embedded TABLE HTML)

//Scrubber
$ScrubbedDescription = trim($description);

$ScrubbedDescription = str_replace(“ \"\"

“, “”, $ScrubbedDescription);
$ScrubbedDescription = str_replace(““, “   “, $ScrubbedDescription);
$ScrubbedDescription = str_replace(“ “, “ “, $ScrubbedDescription);
$ScrubbedDescription = str_replace(“

“, “
“, $ScrubbedDescription);
$ScrubbedDescription = str_replace(” class=\”p\””, “”, $ScrubbedDescription);

printf(“

%s

“,($ScrubbedDescription));

$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;
}
}
}

// EXECUTE PROGRAM

// Create an XML parser
$xml_parser = xml_parser_create();

// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, “startElement”, “endElement”);

// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, “characterData”);

// Grab Querystring Variable to pass
//$QueryVariable1 = substr($_SERVER[‘QUERY_STRING’], 2, strlen($_SERVER[‘QUERY_STRING’]) – 2);

// Open the XML file for reading
$fp = fopen(“http://news.google.com/news?um=1&cf=all&ned=us&hl=en&source=ig&q=”.$QueryVariable1.”&cf=all&output=rss”,”r”)
or die(“Error reading RSS data.”);

// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp))
// Handle errors in parsing
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)));

// Close the XML file
fclose($fp);

// Free up memory used by the XML parser
xml_parser_free($xml_parser);

?>

 

< Back to industry news