i have 2 arrays and a string:
$attribute_ids = array(200,201);
$attribute_names = array("David","Rimma");
$string = "200 2006-2009 boy, 201 girl";
$string = str_replace($attribute_ids, $attribute_names, $string);
output is "David David6-David9 boy, Rimma girl "
expected is "David 2006-2009 boy, Rimma girl "
issue is when array contains 200 and string contains 2000 str_replace replace the string 200 inside 2000.
im trying to replace only the exact same string that is given inside the array "$attribute_ids".
i have tried preg_replace but it did not work.
[200 => "David", 201 => "Rimma"]then split the$stringinto an array by splitting on the spaces, then just do a foreach key, value of the keypair and then replace the string if it matches the key and if it does then replace it with the value from the keypairpreg_replace()with word delimiters regexps in$attribute_idspreg_replace()?