I have a string that I would like to replace with another one if a word within the string is found.
$pattern = array("/jacket/i","/jeans/i");
$replacement = array("jacket","jeans");
$string = 'Red jackets';
$replaced_string = preg_replace($pattern, $replacement, $string);
I know the above wont work but i need to be able to use an array of patterns and replacements.
I would like the $replacement_string to be just “jacket“
Can someone point me out to a solution for this?
Thanks
Maybe if you tweaked your original code just a bit like this:
Putting those
.*in there will clear out the rest of the string… and leave you with just the replacement string you want.