2012-08-04 122 views
0

我想匹配兩個字符串,並且如果找到匹配的匹配狀態。我比較的字符串是使用以下代碼的日期。與if語句匹配的字符串

$feed = simplexml_load_file('http://feeds.feedburner.com/2dopeboyz'); 
foreach($feed->channel->item as $item) { 
    $title = $item->title; 
    $description = $item->description; 
    $pubdate = $item->pubDate; 
    $newDate = date("mdY", strtotime(str_replace("UT", "", $pubdate))); 
    date_default_timezone_set('America/Los_Angeles'); 
    $today = date("mdY"); 

    if ($newdate == $today) { 
     echo 'Match!'; 
    } else { 
     echo "No Match!"; 
    } 
} 

我的問題是,即使字符串相同,任何字符串都不會返回匹配。我怎樣才能得到這個工作?

+1

您是否嘗試回顯$ today和$ newdate以查看它們是否真的匹配? – ngen 2012-08-04 14:13:55

+0

是的,他們和Dogbert發現我的問題 – 2012-08-04 14:15:53

+0

@ Mr.1.0然後請接受他的答案作爲正確答案:) – 2012-08-04 14:23:03

回答

4

變化

if ($newdate == $today) { 

if ($newDate == $today) { 
     ^this 

,你實際上是在宣告$newDate

+0

我難以置信地盯着它,因爲沒有變化,然後看到upvotes,看起來更接近! IDE對於避免這些問題真的很有幫助。 :) 接得好。 – 2012-08-04 14:19:47

+0

@SenthilKumar好點,編輯答案,使其更明顯:) – Dogbert 2012-08-04 14:20:29