In PHP I have this json string with search and replace words
$json = '[{"Original":"test1","Replacement":"test1a"},{"Original":"test2","Replacement":"test2a"}]';
Now I want to do a search and replace in a text string for all items in this json file.
$searchReplaceArray = '[{"Original":"test1","Replacement":"test1a"},{"Original":"test2","Replacement":"test2a"}]';
$text1 = 'Hello test1, let me see if test2 is also replaced...';
$text2 = str_ireplace(array_keys($searchReplaceArray), array_values($searchReplaceArray),$text1);
echo 'Original: ' . $text1 . '<br>';
echo 'Replace: ' . $text2;
I expect $text2 to be: "Hello test1a, let me see if test2a is also replaced..."
However, it does not work. Any help would be appreciated.
json_decode()and gone from there, but its not valid JSON