str_ireplace() is a built in PHP function that performs a case insensitive search and replace on a string or array. It is essentially a case-insensitive version of str_replace().
Syntax
The function signature is:
str_ireplace(array|string $search, array|string $replace, string|array $subject, int &$count = null): string|array
It returns a string or array with all occurrences of $search in $subject replaced by $replace, ignoring case.
Basic Example
<?php
$bodytag = str_ireplace("%body%", "black", "<body text=%BODY%>");
echo $bodytag; // Output: <body text=black>
?>
In this example, %BODY% is matched despite the uppercase letters, because the search for %body% is case-insensitive.
Key Changes in PHP 8.4 / 8.5
The search results do not indicate any behavioral changes or deprecations specific to str_ireplace() in PHP 8.4 or 8.5.
The most recent documented change for this function occurred in PHP 8.2.0. Before 8.2, case folding depended on the server is locale settings (set via setlocale()). Since 8.2, the function only performs ASCII case folding; non-ASCII bytes are compared by their byte value. This means that for multibyte characters (like Ä or é), case-insensitive replacement does not work as one might expect in a UTF-8 context. You may need to use mb_* functions or preg_replace with the i modifier for reliable multibyte handling.