Why does my PHP string comparison fail?
I have the following snippet of code
if ($summary == "CFD funding Interest Paid" ||
$summary == "Commissions" ||
$summary == "Closing trades") {
print $summary.",".$date.",".$reference.",".$description.",".$amount."<br>";
}
else {
print $summary."*<br>";
}
It outputs the following
Commissions* Commissions* Closing trades* Commissions* Closing trades*
How come the strings do not appear to be ma开发者_如何学编程tching?
Perhaps you have leading whitespace? You could trim() that away to see if it helps?
Use the strcmp(str1, str2) function instead.
Add trim() before the if (), it removes unvisible chars like whitespace...
$summary = trim($summary);
if ($summary == "CF...
加载中,请稍侯......
精彩评论