Hey all,
I am having an issue with my PHP code that reads the outputs of an uncommon XML file produced by Meetup.Com. This is the final hurdle that I have with this code. It is ignoring the tree’s hierarchy and instead of reading the item’s event name, it is instead displaying the venue name. I assume it is because the name tag for the venue displays first. What I need is the it to read both the event name and the venue name. I tried a number of things, including listing the item tags like directory structures ("/name" and “/venue/name”), but the code did not like that… I have returned the code to the last point of functionality. In the end, if I can either get the code to respect the tree’s hierarchy or just have it read the third name tags and define it as $item[event_name], a month-long issue would be resolved. Any help is appreciated. Thanks in advance.
XML Output:
<results>
<items>
<item>
<venue>
<address_1>5204 Detroit Rd</address_1>
<state>OH</state>
<zip>44035</zip>
<lat>41.424769</lat>
<repinned>False</repinned>
<phone>440-934-1713</phone>
<name>Ctrl Alt Elite Gaming</name>
<city>Sheffield Village</city>
<id>1540018</id>
<country>us</country>
<lon>-82.081545</lon>
</venue>
<status>upcoming</status>
<description>Cost: $5</description>
<maybe_rsvp_count>0</maybe_rsvp_count>
<waitlist_count>0</waitlist_count>
<updated>1380159785000</updated>
<group>
<who>North Coast Gamers</who>
<join_mode>open</join_mode>
<urlname>North-Coast-Gamers-Cleveland</urlname>
<name>Games! North Coast Gamers - Greater Cleveland Chapter</name>
<id>319720</id>
<group_lat>41.5</group_lat>
<group_lon>-81.6699981689</group_lon>
</group>
<yes_rsvp_count>1</yes_rsvp_count>
<created>1379556175000</created>
<visibility>public</visibility>
<name>Pokemon Pre-Regional TCG Tournament</name>
<id>141025002</id>
<headcount>0</headcount>
<duration>12600000</duration>
<utc_offset>-14400000</utc_offset>
<time>1380990600000</time>
<event_url>http://www.meetup.com/North-Coast-Gamers-Cleveland/events/141025002/</event_url>
</item>
</items>
</results>
PHP Output:
[php]
\n"; // New code - For testing purposes. echo "Title: $rs[title]
\n"; echo "Description: $rs[description]
\n"; echo "Link: $rs[link]
\n"; echo "Updated: $rs[updated]
\n"; echo "
- \n";
foreach ($rs['items'] as $item)
{
// Original code
// echo "\t
- $item[title] \n"; // New code - For testing purposes. // echo "\tVenue: $item[name]
- $item[event_name] - "; $mil = $item[time] / 1000; // Convert time from milliseconds to seconds $tz = $item[utc_offset] / 1000; // Convert timezone from milliseconds to seconds $duration = $item[duration] / 1000; // Convert duration from milliseconds to seconds $time = $mil + $tz; // Convert to U.S. Eastern Timezone $dt = new DateTime("@$time"); // Convert UNIX timestamp to PHP DateTime echo $dt->format('M. j, Y @ g:i A'); // Event date and time start echo " to "; $event_length = $time + $duration; // Adds time and duration $event_end = new DateTime("@$event_length"); // Convert UNIX timestamp to PHP DateTime echo $event_end->format('g:i A'); // Event time end echo "$item[event_datetime] ($item[name]) \n"; // Final Output Desired } if ($rs['items_count'] <= 0) { echo "
- Sorry, no items found in the RSS file. "; } echo "
\n"; // This should be the event name, not its venue. // echo "\tEvent: $item[event_name]
\n"; // Need to create a parse for the third name entry in each item. // echo "\tDescription: $item[description]
\n"; // echo "\tURL: $item[event_url]
\n"; // echo "\tTime: $item[time]
\n"; // echo "\tTimezone: $item[utc_offset]
\n"; // echo "\tDuration: $item[duration]
\n"; // New code - Desired output. echo "\t
"; // you will probably hide this message in a live version } } // =============================================================================== // include lastRSS include "meetup-src.php"; // List of RSS URLs $rss_left = array( 'meetup-rss.xml' ); // Create lastRSS object $rss = new lastRSS; // Set cache dir and cache time limit (5 seconds) // (don't forget to chmod cache dir to 777 to allow writing) $rss->cache_dir = '/security/cache'; $rss->cache_time = 10; // Show all rss files echo "
\n"; foreach ($rss_left as $url) { ShowOneRSS($url); } echo " |
[/php]
PHP Source:
[php]
foreach($this->resultstags as $resultstag)
{
$temp = $this->my_preg_match("'<$resultstag.*?>(.*?)</$resultstag>'si", $out_results[1]);
if ($temp != '') $result[$resultstag] = $temp; // Set only if not empty
}
// If date_format is specified and lastBuildDate is valid
if ($this->date_format != '' && ($timestamp = strtotime($result['lastBuildDate'])) !==-1) {
// convert lastBuildDate to specified date format
$result['lastBuildDate'] = date($this->date_format, $timestamp);
}
// Parse TEXTINPUT info
preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si", $rss_content, $out_textinfo);
// This a little strange regexp means:
// Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beggining tag)
if (isset($out_textinfo[2])) {
foreach($this->textinputtags as $textinputtag) {
$temp = $this->my_preg_match("'<$textinputtag.*?>(.*?)</$textinputtag>'si", $out_textinfo[2]);
if ($temp != '') $result['textinput_'.$textinputtag] = $temp; // Set only if not empty
}
}
// Parse IMAGE info
preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);
if (isset($out_imageinfo[1])) {
foreach($this->imagetags as $imagetag) {
$temp = $this->my_preg_match("'<$imagetag.*?>(.*?)</$imagetag>'si", $out_imageinfo[1]);
if ($temp != '') $result['image_'.$imagetag] = $temp; // Set only if not empty
}
}
// Parse ITEMS
preg_match_all("'<item(| .*?)>(.*?)</item>'si", $rss_content, $items);
$rss_items = $items[2];
$i = 0;
$result['items'] = array(); // create array even if there are no items
foreach($rss_items as $rss_item) {
// If number of items is lower then limit: Parse one item
if ($i < $this->items_limit || $this->items_limit == 0) {
foreach($this->itemtags as $itemtag) {
$temp = $this->my_preg_match("'<$itemtag.*?>(.*?)</$itemtag>'si", $rss_item);
if ($temp != '') $result['items'][$i][$itemtag] = $temp; // Set only if not empty
}
// Strip HTML tags and other stuff from DESCRIPTION
if ($this->stripHTML && $result['items'][$i]['description'])
$result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));
// Strip HTML tags and other stuff from TITLE
if ($this->stripHTML && $result['items'][$i]['title'])
$result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));
// If date_format is specified and pubDate is valid
if ($this->date_format != '' && ($timestamp = strtotime($result['items'][$i]['pubDate'])) !==-1) {
// convert pubDate to specified date format
$result['items'][$i]['pubDate'] = date($this->date_format, $timestamp);
}
// Item counter
$i++;
}
}
$result['items_count'] = $i;
return $result;
}
else // Error in opening return False
{
return False;
}
}
}
?>
[/php]
Just a heads up, this is a modified version of LastRSS 0.9.1 by Vojtech Semecky. It is a free download, you just have to search for it.