Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to compare strings ignoring case

Short answer

Convert both strings to lowercase and compare:

<?php
 
var_dump(mb_strtolower('Привет') === mb_strtolower('ПРИВЕТ'));

Output:

bool(true)

For ASCII text

strcasecmp() returns 0 if the strings are equal ignoring case:

<?php
 
var_dump(strcasecmp('Hello', 'HELLO') === 0);

Output:

bool(true)

Functions used in this recipe

  • mb_strtolower — Converts a string to lowercase for any alphabet.
  • strcmp — Compares two strings.

Thanks for reading!

Donate to the site — we work hard for you.