str_ireplace()
str_ireplace() — Case-insensitive version of str_replace().
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value.
Signature
str_ireplace(array|string $search, array|string $replace, string|array $subject, int &$count = null): string|array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $search | array|string | The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles. |
| $replace | array|string | The replacement value that replaces found search values. An array may be used to designate multiple replacements. |
| $subject | string|array | The string or array being searched and replaced on, otherwise known as the haystack. |
| &$count | int | If passed, this will be set to the number of replacements performed. |
Return value
Returns a string or an array of replacements.
Example
A runnable snippet:
$bodytag = str_ireplace("%body%", "black", "<body text=%BODY%>"); echo $bodytag; // <body text=black>
Changelog
| Version | Change |
|---|---|
| 8.2.0 | Case folding no longer depends on the locale set with setlocale(). Only ASCII case folding will be done. Non-ASCII bytes will be compared by their byte value. |
See also
str_replace(), preg_replace(), strtr()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page str_ireplace() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.