Jump to content


Photo

Case sensitive problem


  • Please log in to reply
4 replies to this topic

#1 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 05 September 2006 - 11:20 PM

Hi,

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


<?php 

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

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


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?

#2 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 05 September 2006 - 11:46 PM

Never mind...I've figured it out

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 11:48 PM

... and for the benegit of the rest of us, the solution was ...
Legend has it that reading the manual never killed anyone.
My site

#4 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 06 September 2006 - 12:01 AM

The solution was.....(I was getting to the post ;))

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

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

?>

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

<?php

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

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

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

$compare DOES equal 0, so the redirect occurs


#5 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 06 September 2006 - 12:08 AM

Whoops, I made a typo in printing above,
the final solution shoiuld be

?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();
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users