Issue
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!
But it's supposed to come back as
zovty, bedankt! === zovty, bedankt!
So the script doesn't seem to detect it as having found a match. What did I do wrong?
Solution
I guess one of the strings may contain trailing whitespace or newline characters, so try this:
if (trim($value) == trim($titelzor)) ...
Answered By - Blagovest Buyukliev
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.