Jump to content

Case sensitive problem


realjumper

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?
Link to comment
https://forums.phpfreaks.com/topic/19832-case-sensitive-problem/
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
Link to comment
https://forums.phpfreaks.com/topic/19832-case-sensitive-problem/#findComment-86795
Share on other sites

Archived

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

×
×
  • Create New...

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.