开发者

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...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜