ie from this;
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
to this;
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,<span class="full> but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>
Here's part of the code
Code: Select all
/**
* Store a single item in the database.
* @param Lots, see definition. Everything is a string, exceptions:
* @param $dc_date integer representing the date/time as a unix timestamp.
*/
function saveRssItem($title, $link, $description, $dc_creator, $dc_date, $dc_subject) {
$qry = "
INSERT INTO items
(
title,
link,
description,
dc_creator,
dc_date,
dc_subject
)
VALUES
(
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($link)."',
'".mysql_real_escape_string($description)."',
'".mysql_real_escape_string($dc_creator)."',
'".mysql_real_escape_string($dc_date)."',
'".mysql_real_escape_string($dc_subject)."'
)
";
$this->query($qry);
}
}
/**
* Quick'n'Dirty RSS reader and parser. Simply reads in the items in a feed.
*/
class RSSParser {
var $saveItems = array(
"title" => "string",
"link" => "string",
"description" => "string",
"dc:creator" => "string",
"dc:date" => "date",
"dc:subject" => "string",
);
/**
* Read and parse a RSS feed which $url points at (may be an URL or local file)
* @param $url string containing the URL to the RSS feed. May be an URL or local file
*/
function RSSParser($url) {
$this->read($url);
$this->readItems();
}
/**
* Construct a new empty RSS item
* @return a new empty assoc. array representing an rss item
*/
function newItem() {
$retItem = array();
foreach(array_keys($this->saveItems) as $key) {
$retItem[$key] = "";
}
return($retItem);
}
/**
* Read a RSS file/url and make a big string of it so it can be parsed.
* @param $url string containing the URL to the RSS feed. May be an URL or local file
*/
function read($url) {
$this->rssData = implode("", file($url));
}
/**
* Read <item> segments from the RSS file and stuff them in an array.
*/
function readItems() {
if (!isset($this->rssData)) {
return(-1);
}
$this->rssItems = array();
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$this->rssData,$values,$tags);
xml_parser_free($parser);
// Loop through all the elements in the RSS XML file. If an <item> tag
// is found, it's children will be added to a array until the closing
// tag is found. Then the array is added to a list of items
// ($this->rssItems).
for ($i=1; $i < count($values); $i++) {
$tagName = "";
$tagType = "";
$tagValue = "";
if (array_key_exists("tag", $values[$i])) {
$tagName = $values[$i]["tag"];
}
if (array_key_exists("type", $values[$i])) {
$tagType = $values[$i]["type"];
}
if (array_key_exists("value", $values[$i])) {
$tagValue = $values[$i]["value"];
}
if ($values[$i]["tag"] == "item" && $values[$i]["type"] == "open") {
// Looks like we found an <item> tag. Create a new array to
// store it's children values as they will be found on the next
// iteration of the loop.
$rssItem = $this->newItem();
}
if ($values[$i]["tag"] == "item" && $values[$i]["type"] == "close" && isset($rssItem)) {
// </item> tag closed. Store the read item information.
$this->rssItems[] = $rssItem;
unset($rssItem); // No item information will be saved when this doesn't exist.
}
if (array_key_exists($tagName, $this->saveItems) && isset($rssItem)) {
// Found a tag that we want to store and that's part of an
// <item>. Save it.
switch($this->saveItems[$tagName]) {
case "string":
$rssItem[$tagName] = $tagValue;
break;
case "date":
$rssItem[$tagName] = strtotime($tagValue);
break;
default:
print("Don't know how to handle type ".$this->saveItems[$tagName].". Aborting.");
exit(1);
break;
}
}
}
}
}
$db = new RSSDB($db_hostname, $db_username, $db_password, $db_database);
$parser = new RSSParser($file);
$db->clearRssItems(); // Delete old RSS items.
foreach($parser->rssItems as $rssItem) {
$db->saveRssItem(
$rssItem["title"],
$rssItem["link"],
$rssItem["description"],
$rssItem["dc:creator"],
$rssItem["dc:date"],
$rssItem["dc:subject"]
);
}