I have the following code below that works and pulls the data from an xml file. My question now is how can I only display the top/first 10 or 5 results? Or last 10/5 results?
I also have part of the xml doc reading.
<div id="filmcalls_feed">
<?php
//set a max value of 5 listings if variable is empty
if (empty($xmlmaxcnt)){
$xmlmaxcnt=5;
}
$file = "http://www.filmcalls.com/events.xml";
//echo $file;
$map_array = array(
"BOLD" => "B",
"EMPHASIS" => "I",
"LITERAL" => "TT"
);
$current = "";
$sLink = "";
$sDescription = "";
$sTitle = "";
$iCnt = 0;
$GLOBALS['Counter'] = 0;
function startElement_filmcalls($parser, $name, $attrs)
{
global $current;
$current = $name;
if ($name == "ITEM") { echo ""; }
if ($name == "LINK") { echo ""; }
if ($name == "TITLE") { echo ""; }
if ($name == "DESCRIPTION") { echo ""; }
}
function endElement_filmcalls($parser, $name)
{
$iCnt = $GLOBALS['Counter'];
if ($name == "LINK") { echo ""; }
if ($name == "TITLE") { echo ""; }
if ($name == "ITEM") { echo ""; }
//$iFound = strpos($GLOBALS['sDescription'], "FILM FESTIVAL CALENDAR");
//if ($GLOBALS['Counter'] > 0 && $GLOBALS['Counter'] < 6) {
if ($name == "DESCRIPTION") {echo "<a href=\"" . urldecode($GLOBALS['sLink']) . "\" target='_blank'>" . $GLOBALS['sTitle'] . "</a><br>" . $GLOBALS['sDescription'] . "<br><br>"; $GLOBALS['sTitle'] = ""; $GLOBALS['sDescription'] = "";}
//}
$iCnt++;
//echo $iCnt & " - " & $GLOBALS['sDescription'] & "<br>";
$GLOBALS['Counter'] = $iCnt;
}
function characterData_filmcalls($parser, $data)
{
global $current;
if (!(ord($data) == 10)){
if ($current == "TITLE") { $GLOBALS['sTitle'] .= $data; }
if ($current == "DESCRIPTION") { $GLOBALS['sDescription'] .= $data; }
if ($current == "LINK") { $GLOBALS['sLink'] = $data;}
}
}
$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the tag in $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement_filmcalls", "endElement_filmcalls");
xml_set_character_data_handler($xml_parser, "characterData_filmcalls");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>
</div>
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>FilmCalls</title>
<link>http://www.filmcalls.com/</link>
<description>FILM FESTIVAL CALENDAR powered by FilmCalls.com </description>
<image>
<title>FilmCalls</title>
<url>http://www.filmcalls.com/images/rss_logo.gif</url>
<link>http://www.filmcalls.com</link>
</image>
<item>
<title>Vancouver Int'l Film Festival</title>
<link>http://www.viff.org/</link>
<description>Vancouver, Canada | Sep 25-Oct 10, 2008</description>
</item>
<item>
<title>Lyon Int'l Film Festival</title>
<link>http://www.hors-ecran.com/</link>
<description>Lyon, France | Sep 30-Oct 12, 2008</description>
</item>
</channel>
</rss>