Why does my PHP string comparison fail?

I have the following code snippet

if ($summary == "CFD funding Interest Paid" ||
    $summary == "Commissions" ||
    $summary == "Closing trades") {
    print $summary.",".$date.",".$reference.",".$description.",".$amount."<br>";  
}
else {
    print $summary."*<br>";
}

It displays the following

Commissions *
Commissions *
Closing trades *
Commissions *
Closing trades *

Why don't the lines match?

+3
source share
3 answers

Perhaps you have leading spaces? You can remove () to see if this helps?

+8
source

Add trim()in front if (), it removes invisible characters like spaces ...

$summary = trim($summary);
if ($summary == "CF...
+5
source

Use function instead strcmp(str1, str2).

0
source

All Articles