Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

str_replace()

Replace case-sensitive literal strings in search-array order.

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

Syntax

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

Replace case-sensitive literal strings in search-array order. A later search can therefore replace text produced by an earlier replacement. Missing replacement entries act as empty strings and the optional count totals all replacements. This is not a simultaneous mapping.

Signature

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

Example output

["c",3,"a"]

Examples

<?php
$out=str_replace(["a","b","!"],["b","c"],"a!",$count);
echo json_encode([$out,$count,str_replace("A","x","a")]);

Result

["c",3,"a"]

Sources