strtolower($a)==strtolower($b)!=匹配?
好的,我有一个函数,可以比较值并返回结果,无论大小写,即: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. <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]));
虽然它看起来更复杂,它实际上只是一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的字符串中是否有尾随空格?也许将
trim()
与strtolower()
一起嵌套可以解决这个问题?如果您在 HTML 输出中查看此内容,请查看源代码并确保其中没有 HTML 实体将其搞乱(即“设施间转移”和“设施间转移”并不相同,但是可能看起来与 HTML 中呈现的相同)。最后的选择是“升级”到 mb_strtolower 并查看是否是编码问题。
Is there any trailing whitespace on your strings? Perhaps nesting a
trim()
along with astrtolower()
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.打印出 expval 和 actval 的字节(例如使用
urlencode
)。有很多不同的字符看起来完全相同(例如,普通空格和不间断空格,或 c、es 和 es 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).