str_ireplace
Replaces a substring ignoring case.
Syntax
str_ireplace(array|string $search, array|string $replace, string|array $subject): string|arrayParameters
| Parameter | Type | Description |
|---|---|---|
| $search | array|string | What to replace. |
| $replace | array|string | What to replace it with. |
| $subject | string|array | The 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 PHPNotes
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.