0

Hi everyone,

Having difficulty comparing two strings (Inside variables) in php.
I have tried several methods, one being strcmp but I think I was doing that incorrectly, and now the simple === / == comparison methods.

Here is the code:

<?php
		
		if ($pubinfo_username === $currentuser) {
		echo "<img alt=\"Remove this post\" height=\"20\" src=\"../images/btns/x.png\" width=\"25\">";
		} else {
		}
		?>

That is the simple === strict comparison between strings, personally I see no reason as to why this doesn't work, but clearly something is wrong.

Any help is much appreciated!

Cheers, Jack.

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by diafol
0

Sometimes it isn't the code per se. It can be because there are blanks or special characters or capitals in one of the strings . The code is simple in the extreme so it isn't very likely that anything is wrong with the compare itself.

0

Ok, do you know of any other methods in which i can use that will not check for caps/punctuation/symbols etc?

Cheers, Jack

0

Hi Jack,

This may seem over obvious but are you sure the variables you are getting are what you are expecting?
Try echoing both variables before the IF statement.

0

Echoing both variables out before the comparison to see if they at least look similar is a good suggestion?
Getting the ord of each and comparing could be useful:

$no= mb_strlen($var1,"UTF-8");
for($r=0;$r<$no;$r++)echo ord($var[$r]);
echo "<br />";
$no= mb_strlen($var2,"UTF-8");
for($r=0;$r<$no;$r++)echo ord($var2[$r]);

There again you could echo an md5 of each to see if they truly are the same.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.