开发者

strtolower($a)==strtolower($b)!=match?

开发者 https://www.devze.com 2023-02-09 06:43 出处:网络
OK, i have a function that compares values and returns the results, regardless of case, ie: Interfacility Transfer = INTERFACILITY TRANSFER here is the function:

OK, i have a function that compares values and returns the results, regardless of case, ie: Interfacility Transfer = INTERFACILITY TRANSFER here is the function:

function fncResult ($expVal, $actVal)
{
    $negNulls=array("-5","-10","-15","-20","-25");
    if (!in_array($expVal, $negNulls))
    {
        if(strtolower($expVal)==strtolower($actVal))
        {
            echo "
            <td class='match' title='The values match.'>Match</td>
        </tr>";
        }
        else
        {
            echo "
                            <td class='notMatch'  title='The values do not match.'>Not Match<br />No Match</td>
                        </tr>";
        }
    }
    else
    {
        echo "
            <td class='null'  title='The value in the XML was a negative null.'>Negative Null</td>
        </tr>";
    }
}

It works about 99% of the time except when it comes to this:

//--Type of service requested
        echo "
            <tr>
                <td>E02_04</td>
                <td>Type of Service Requested</td>
                <td>36. &lt;Nature of Call&gt;</td>
                <td>$fldServReq</td>
                <td>".fncGrabNemsis("E02_04",$fldServReq,$local)."</td>
                <td>".fncIsSet($CZ_E02_04[1])."</td>";
        fncResult(fncGrabNemsis("E02_04",$fldServReq,$local),fncIsSet($CZ_E02_04[1]));

Although it looks more开发者_运维问答 complicated, it really is just a strtolower($expVal)==strtolower($actVal), comparison. When I echo the values being compared, I get: "interfacility transfer" and "interfacility transfer" and "No Match"... WTF? Could it be because the first value is coming from a XML (UTF-8) and the second is from a DB (?) I have no idea what to do and am incredibly frustrated since this a simple task. Thanks for any help!


Is there any trailing whitespace on your strings? Perhaps nesting a trim() along with a strtolower() would clear that up? If you're looking at this in HTML output, take a look at the source and make sure there's not an HTML entity in there messing it up (i.e. "interfacility transfer" and "interfacility&nbsp;transfer" are not the same, but may look the same rendered in HTML).

The final option is to "upgrade" to the mb_strtolower and see if it is an encoding issue.


Print out the bytes of expval and actval (with urlencode, for example). There are a lot of different characters that look exactly the same (for example, normal space and non-breaking space, or c, es and roman 100).

0

精彩评论

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