Im finding keyword "paintball" in a string, and wrapping it in span tags to change it colour to red like this...
$newoutput = str_replace("Paintball", "<span style=\"color:red;\">Paintball</span>", $output);
echo $newoutput;
Which works, but people are writing it in the field as "Paintball", "paintball", "Paint Ball", "paint ball" etc.
Is there a better way of doing this rather than repeating it for every word?
Ideally something like...
$words = "Paintball", "paintball", "Paint Ball", "paint ball";
$newoutput = str_replace("($words)", "<span>$1</span>", $output);
But im not sure how to write it.
Ok, so a mixture of answers got me here...
$newoutput = preg_replace("/(paint\s*ball|airsoft|laser\s*tag)/i", "<span>$1</span>", $output);
echo $newoutput;
And it works perfectly, thank you very much!