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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

str_ireplace(array|string $search, array|string $replace, string|array $subject, int &$count = null): string|array

Parameters

ParameterDescription
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

Fix capitalizationTry it yourself
<?php
echo str_ireplace("php", "PHP", "php is fun. Php is fast."), "\n";

Output

PHP is fun. PHP is fast.
Mask words in any caseTry it yourself
<?php
$comment = "This is SPAM and more Spam";
echo str_ireplace("spam", "***", $comment), "\n";

Output

This is *** and more ***

Version history

VersionChange
PHP 5.0Added

Was this page helpful?