-1

I have an if statement in my website. And what I want, is that he won't make distinction in capital letters. My if statement:

<?php
$nameOne = "JOHN";
$check = "john";
if($nameOne == $check){
 echo 'No distinction';
} else {
  echo 'distinction ';
}
?>

So, I want to echo 'No distinction'.

MajorSin
  • 71
  • 9
  • @funk No, it isn't a typo. What if `$nameOne` john contains? Then I want to echo "No distinction". – MajorSin Mar 25 '18 at 16:58
  • 2
    You were not able to do a simple google search for "php case insensitive string comparison" but ask _here_? – arkascha Mar 25 '18 at 16:59

2 Answers2

1

You can make the comparison using strtolower() on both strings

if (strtolower($nameOne) == strtolower($check))
DrKey
  • 3,365
  • 2
  • 29
  • 46
0

You can use the solution suggested by @NicoHaase

<?php
$var1 = "Hello";
$var2 = "hello";
if (strcasecmp($var1, $var2) == 0) {
    echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}
?>

https://secure.php.net/manual/en/function.strcasecmp.php

SuperDJ
  • 7,488
  • 11
  • 40
  • 74