strtolower($a)==strtolower($b)!=匹配?

发布于 2024-10-16 05:00:30 字数 1628 浏览 4 评论 0原文

好的,我有一个函数,可以比较值并返回结果,无论大小写,即:Interfacility Transfer = INTERFACILITY TRANSFER 这是该函数:

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>";
    }
}

它在大约 99% 的时间内工作,除非涉及到这个:

//--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]));

虽然它看起来更复杂,它实际上只是一个 strtolower($expVal)==strtolower($actVal) 比较。当我回显正在比较的值时,我得到:“设施间转移”和“设施间转移”和“不匹配”...... WTF?难道是因为第一个值来自 XML (UTF-8),第二个值来自 DB (?) 我不知道该怎么做,并且非常沮丧,因为这是一项简单的任务。感谢您的帮助!

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. <Nature of Call></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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2024-10-23 05:00:30

您的字符串中是否有尾随空格?也许将 trim()strtolower() 一起嵌套可以解决这个问题?如果您在 HTML 输出中查看此内容,请查看源代码并确保其中没有 HTML 实体将其搞乱(即“设施间转移”和“设施间转移”并不相同,但是可能看起来与 HTML 中呈现的相同)。

最后的选择是“升级”到 mb_strtolower 并查看是否是编码问题。

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

哆兒滾 2024-10-23 05:00:30

打印出 expval 和 actval 的字节(例如使用 urlencode)。有很多不同的字符看起来完全相同(例如,普通空格和不间断空格,或 ceses decodeunicode.org/en/u+217d" rel="nofollow">罗马 100)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文