Reputation: 604
I have a (probably) simple PHP question. I'm pulling a schedule from an RSS feed. The RSS output looks like such:
17th Jan 2011 : Day 2
18th Jan 2011 : Day 3
19th Jan 2011 : Day 4
20th Jan 2011 : Day 5
I'm trying to remove all the information so only "Day x" remains. The schedule runs on an 8 day cycle, however I am limiting the RSS parser to only one Day so I get the current day.
I'm using this to pull the RSS:
$rss->parse();
$rss->showStories('1');
After a bit of tinkering I came up with this.
$i=1;
while($i<=8) {
if (preg_match("/Day 3/i", "Day ".$i)) {
echo $i;
} else {
$i++;
}
}
Obviously the problem starts here:
if (preg_match("/Day 3/i", "Day ".$i)) {
I want this to find what the current schedule day is and then display corresponding data. Am I approaching this the right way could someone point me in the right direction please?
Thanks!
EDIT: Fixed code is below for anyone that wants it:
<?php
$url = "";
$rss = simplexml_load_file($url);
if($rss) {
$items = $rss->channel->item;
foreach($items as $item) {
foreach ($item->title as $story) {
if (!preg_match(date("/jS M Y/"), $story)) continue;
preg_match("/Day (\d+)/", $story, $m);
echo $m[1]; // should print "2" if today is January 17
break; // stop searching
}
}
}
?>
Upvotes: 0
Views: 128
Reputation: 6837
You don't say which RSS library you are using, but something along the lines of
foreach ($rss->stories as $story) {
// skips stories that are not today
if (!preg_match(date("/jS M Y/"), $story)) continue;
preg_match("/Day (\d+)/", $story, $m);
echo $m[1]; // should print "2" if today is January 17
break; // stop searching
}
could work. But without any more code it is hard to help further.
Upvotes: 2