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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.