SyntaxStudy
Sign Up
Home PHP Reference str_replace()

str_replace()

function

Replaces all occurrences of the search string with the replacement string. Case-sensitive.

Syntax

str_replace(mixed $search, mixed $replace, mixed $subject): mixed

Example

php
<?php
echo str_replace('World', 'PHP', 'Hello World'); // Hello PHP

$search  = ['apple', 'banana'];
$replace = ['orange', 'grape'];
echo str_replace($search, $replace, 'I like apple and banana');
// I like orange and grape

echo str_ireplace('HELLO', 'Hi', 'Hello World'); // Hi World