PHP 8 reference · String Functions
PHP str_ireplace() Function
Replace every occurrence of a search string, ignoring upper and lower case. Otherwise works like str_replace().
PHP 8 Since 5.0
Syntax
str_ireplace(array|string $search, array|string $replace, string|array $subject, int &$count = null): string|array
Parameters
| Parameter | Description |
|---|---|
search |
The value(s) to find, in any case. |
replace |
The replacement(s). |
subject |
The string or array to search in. |
count optional |
Set to the number of replacements. |
Return value
The string (or array) with replacements made.
Examples
<?php
echo str_ireplace("php", "PHP", "php is fun. Php is fast."), "\n";
Output
PHP is fun. PHP is fast.
<?php
$comment = "This is SPAM and more Spam";
echo str_ireplace("spam", "***", $comment), "\n";
Output
This is *** and more ***
Version history
| Version | Change |
|---|---|
| PHP 5.0 | Added |
Related
str_replace()· Replace every occurrence of a search string with a replacement. Accepts arrays to make several replacements at once.stripos()· Find the position of the first occurrence of a substring, ignoring case. Returns false when there's no match.- PHP Strings · tutorial