Jump to content

Archived

This topic is now archived and is closed to further replies.

realjumper

Case sensitive problem

Recommended Posts

Hi,

According to the manual this should work.......

[code]

<?php

$a = 'a';
$b = 'A';

if (strcasecmp($a, $b) == 0) {
 echo '$a is equal to $b in a case-insensitive string comparison';
}

[/code]

If I comment out the 'echo.....' the page displays. With the echo in place nothing displays, and I don't know why.

All I am tring to do is to (utimately) have $a equal $b when $a might be in caps and $b might be in lower case. I wish to return True that $a equals $b regardless of case. I'm sure I have used this before but I can't find the code in my library. Can anyone help?

Share this post


Link to post
Share on other sites
... and for the benegit of the rest of us, the solution was ...

Share this post


Link to post
Share on other sites
The solution was.....(I was getting to the post ;))

That this piece of code returns '0' if the comparison is true.....
[code]
<?php

$a = 'a';
$b = 'A';
echo strcasecmp("$a","$b");

?>
[/code]

The above returns '0'. So.....

[code]
<?php

$a = 'a';
$b = 'b';

$compare = strcasecmp("$a","$b");

if ($compare == '0')
{
Header("Location: yipee_you_are_logged_in.php");
exit();
}
?>
[/code]

$compare DOES equal 0, so the redirect occurs

Share this post


Link to post
Share on other sites
Whoops, I made a typo in printing above,
the final solution shoiuld be

[code]
?php

$a = 'a';
$b = 'A';  // my typo was here

$compare = strcasecmp("$a","$b");

if ($compare == '0')
{
Header("Location: yipee_you_are_logged_in.php");
exit();
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.