You can also use preg_replace_callback. Str replace doesn't accept arguments in the replacement string.
$key = array($value1, $value2, …);
$regex = addslashes(implode('|', $key));
$content = preg_replace_callback(
"/$regex/",
function ($matches) {
return '<span class="key">'.$matches[0].'</span>';
},
$content
);
bitWorking has a better answer though if you can make each value in the array it's own regular expression.