<?php

?>

Run Instance

str_replace("(", "第2段": "Syntax",find,replace,string,count)
Parameters Description
find Required. Specifies the value to be searched for.
replace Required. Specifies the replacement find The value of the value in
string Required. Specifies the string to be searched.
count Optional. Variable for counting the replacement number.

Technical Details

Return Value: Returns a string or array with the replacement values.
PHP Version: 4+
Update Log:

Newly added in PHP 5.0: count parameters.

Before PHP 4.3.3, the function's find and replace Trouble will occur when all parameters are arrays, which will cause an empty find The internal pointer index is not changed replace It is ignored when used on an array. The new version will not have this problem.

Starting from PHP 4.0.5, most parameters can be an array.

More Examples

Example 1

Use with an array count The str_replace() function of variables:

<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacement count: $i";
?>

Run Instance

Example 2

Use the str_replace() function with fewer elements to be replaced than the elements found:

<?php
$find = array("Hello","world");
$replace = array("B");
$arr = array("Hello","world","!");
print_r(str_replace($find,$replace,$arr));
?>

Run Instance