本文介绍了字符串比较不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试比较 wordpress 中的帖子标题,以避免创建标题已存在的帖子.
I am trying to compare post titles in wordpress to avoid creating a post with a title that already exists.
foreach ($postnamearray as $value)
{
if($value === $titelzor)
{
echo' '.$value.' === '.$titelzor.' ';
}
else
{
echo' '.$value.' != '.$titelzor.' <br /> ';
}
}
但是,它不起作用!当应该找到匹配项时,它会返回(对不起荷兰语文本):
However, it's not working! When a match is supposed to be found, it comes back as (sorry for dutch text):
zovty, bedankt! != zovty, bedankt!
但它应该返回
zovty, bedankt! === zovty, bedankt!
因此脚本似乎没有将其检测为已找到匹配项.我做错了什么?
So the script doesn't seem to detect it as having found a match. What did I do wrong?
推荐答案
我猜其中一个字符串可能包含尾随空格或换行符,所以试试这个:
I guess one of the strings may contain trailing whitespace or newline characters, so try this:
if (trim($value) == trim($titelzor)) ...
这篇关于字符串比较不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!