Skip to content
Advertisement

Ignore case sensitivity when comparing strings in PHP

I’m trying to compare words for equality, and the case [upper and lower] is irrelevant. However PHP does not seem to agree! Any ideas as to how to force PHP to ignore the case of words while comparing them?

JavaScript

Is there a way to carry out the replace even if the case is different?

Advertisement

Answer

Use str_ireplace to perform a case-insensitive string replacement (str_ireplace is available from PHP 5):

JavaScript

To case-insensitively compare strings, use strcasecmp:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement