HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

str_ireplace

Description

The str_ireplace of String for PHP case-insensitive version of str_replace().

Syntax

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

Parameters

The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.

replace

The replacement value that replaces found search values. An array may be used to designate multiple replacements.

subject

The string or array being searched and replaced on, otherwise known as the haystack. If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.

count

If passed, this will be set to the number of replacements performed.

Return

Returns a string or an array of replacements.

Examples

1 · search replace subject

<?

$search = "case";
$replace = "replace";
$subject = "case Case CASE";

$return = str_ireplace($search, $replace, $subject);

echo $return;
replace replace replace

2 · count

<?

$search = "case";
$replace = "replace";
$subject = "case Case CASE";

$return = str_ireplace($search, $replace, $subject, $count);

echo $count;
3

3

<?

$search = array("search1", "search2", "search3");
$replace = "replace";
$subject = "search1 search2 search3";

$return = str_ireplace($search, $replace, $subject);

echo $return;
replace replace replace

4

<?

$search = array("search1", "search2", "search3");
$replace = array("replace1", "replace2", "replace3");
$subject = "search1 search2 search3";

$return = str_ireplace($search, $replace, $subject);

echo $return;
replace1 replace2 replace3

5

<?

$search = array("\r\n", "\n", "\r"); // \r\n first
$replace = "<br>";
$subject = "line\nline\rline\r\nline";

$return = str_ireplace($search, $replace, $subject);

echo $return;
line<br>line<br>line<br>line

6

<?

$search = array('a', 'b', 'c', 'd', 'e');
$replace = array('b', 'c', 'd', 'e', 'f');
$subject = 'a';

$return = str_ireplace($search, $replace, $subject);

echo $return;
f

7

<?

$search = array('a', 'p');
$replace = array('apple', 'pear');
$subject = 'a p';

$return = str_ireplace($search, $replace, $subject);

echo $return;
apearpearle pear