I have a small exert of text that I want to check for an item within an array and then put strong tags around that item, here is what I'm trying so far in php but I don't think the match part is working? $text = "10 euro is the cost"; $patterns = array("pounds", "euro", "dollar"); $found = preg_match("/^([0-9]+) ".$patterns."/", $text); echo str_replace($found, "<strong>".$found."</strong>", $text); // Should echo <strong>10 euro</strong> is the cost PHP: Any ideas on what's not correct above? Thanks
Concerning processing would it be better to do the foreach item in array or just make the it non dynamic and use: ([item1|item2|item3|item4]+) Code (markup): If it's for about 30 items?
Try this $text = "10 euro is the cost"; $patterns = array("pounds", "euro", "dollar"); $replacements = array(); foreach($patterns as &$p) { $replacements[] = "<strong>$p</strong>"; $p = '#' . $p . '#'; } $s = preg_replace($patterns, $replacements, $text); Code (markup):