开发者

Why does my PHP string comparison fail?

开发者 https://www.devze.com 2023-03-06 16:19 出处:网络
I have the following snippet of code if ($summary == \"CFD funding Interest Paid\" || $summary == \"Commissions\" ||

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

精彩评论

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