I have a string of values separated by semicolon.
$str = 'value 12; another value; yet one more one; val5';
I also have an array where the keys correspond to the values in the string above.
How do I replace the values in the string with the values from the array? Now, I think I can explode the string by semi-colon and trim the space
$arr = array_map('trim', explode(';', $str));
Do I need to run the array through a loop and use the values as keys and then implode it back? Is there a faster way?
2
Answers
str_replace() will accept arrays of tokens and values to replace them. Thus
See: https://3v4l.org/kN8VW
I think using
str_ireplace
can help you the most and code should look like below.