|
str_replace () PHP functions
Function str_replace () replaces the values in a search string from a string. Str_replace usually be replaced by a value found with a defined or specified. Position is indicated in all cases where no appropriate definition of complex rules are recommended when ereg_replace () or preg_replace ()
PHP SYNTAX :
str_replace(search,replace,initialstring,count);
search = Required. Specifies the value to find ;
replace = Required. Specifies the value to replace the value in find ;
initialstring = Required. Specifies the string to be searched ;
count = Optional. A variable that counts the number of replacements ; EXAMPLES FOR str_replace PHP function :
1.
<?php
echo str_replace("red","blue","The sky is red !");
?>
Result:
The sky is blue !
2.
<?php
$list_array = array("two","one","three","four","two");
print_r(str_replace("two","nine",$list_array,$i));
echo "Replacements: $i";
?>
Array
(
[0] => nine
[1] => one
[2] => three
[3] => four
[4]=> nine
)
Replacements: 2
3.
<?php
$initialstring='The sky is red !';
echo str_replace("red","blue",$initialstring);
?>
the output is:
The sky is blue!
|