Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

str_ireplace

Replaces a substring ignoring case.

Syntax

str_ireplace(array|string $search, array|string $replace, string|array $subject): string|array

Parameters

ParameterTypeDescription
$searcharray|stringWhat to replace.
$replacearray|stringWhat to replace it with.
$subjectstring|arrayThe source string.

Return value

string|arrayThe string with the replacements.

Examples

Case is ignored:

<?php
 
echo str_ireplace('php', 'PHP', 'I like Php and php');

Output:

I like PHP and PHP

Notes

Plain str_replace() would replace only an exact match. For non-ASCII text ignoring case, use preg_replace() with the ui modifiers.

See also

  • str_replace — Replaces all occurrences of a substring with another string.
  • preg_replace — Replaces everything that matches a regular expression.

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.