我試圖確定兩個字符串是否匹配,即使當我將它們打印出來時,它們也是相同的,但仍然表示它們不匹配。我試着投他們兩個字符串,我試圖用「===」而不是「==」,但也解決了這個問題...PHP中的變量比較問題
if(preg_match("#^Availability:#", $test)) {
//just to note: $test = "Availability: Lorem Ipsum";
$nid = 1;
$prep = explode("Availability:", $test);
$orig = node_load($nid);
print $prep[1]; //Prints Lorem Ipsum
print($orig->title); //Prints Lorem Ipsum
if((string)$orig->title == (string)$prep[1]) {
print 'ok';
} else {
print 'nope'; //Always prints nope
}
...
可能是換行符/空格問題。你可以對兩個值做一個trim(),看看它們是否匹配? – 2011-05-18 15:26:08