Assuming I have a string
$str = "abc*efg*hij*";
and an array
$arr = array("123","456","789");
Now I want to replace the *
s in $str
with the elements in $arr
according to the positions.The first *
replaced with $arr[0]
,the second replaced with $arr[1]
etc.I check the function str_replace,though it accepts arrays as parameters but I found it did not work.And I cannot just use
$newstr = "abc{$arr[0]}efg{$arr[1]}hij{$arr[2]}"
because the real $str
may be quite a long string with lots of *
.Any good ideas?Thanks.