Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

str_ireplace()

Replace literal matches without case sensitivity for ASCII letters.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

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

Replace literal matches without case sensitivity for ASCII letters. Since PHP 8.2 case folding is independent of locale and does not extend to arbitrary Unicode letters. The optional count receives the total replacements, and an array subject returns an array with the original keys.

Signature

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

Example output

[{"a":"XX","b":"X"},3,"É"]

Examples

<?php
$out=str_ireplace("ab","X",["a"=>"ABab","b"=>"Ab"],$count);
echo json_encode([$out,$count,str_ireplace("\u{00E9}","x","\u{00C9}")],JSON_UNESCAPED_UNICODE);

Result

[{"a":"XX","b":"X"},3,"É"]

Sources