Reputation: 4342
I am trying to return twitter titles based on today's date only. I have made the following code below, but it returns every title no matter if its today's date or not.
$dom = new DOMDocument();
@$dom->loadHTMLFile('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=google');
$xml = simplexml_import_dom($dom);
$twitter = $xml->xpath("//item");
foreach ($twitter as $item) {
$timezone = new DateTimeZone('America/Los_Angeles');
$date = new DateTime($item->pubdate);
$date->setTimeZone($timezone);
$twitter_date = $date->format("F j Y");
$todays_date = date("F j Y");
if ($twitter_date == $todays_date) {
foreach ($twitter as $item) {
$text = $item->title;
echo $text.'<br />';
}
}
}
Upvotes: 2
Views: 57
Reputation: 12059
You are looping again through EVERY $twitter
inside the if
statement. Try removing the foreach
tag inside and just using the current $item
:
if ($twitter_date == $todays_date) {
$text = $item->title;
echo $text.'<br />';
}
Upvotes: 1