It would be a lot more efficient to just use the string replacement functions such as str_replace() or str_ireplace()
$replace = array('a', 'b');
$replacements = array('<b>a</b>', '<b>b</b>');
$subject = "You are the best At BaseBall";
$subject= str_ireplace($replace, $replacements, $subject);
echo $subject;
or
$replace = array('a', 'b');
$subject = "You are the best At BaseBall";
foreach($replace as $x) {
$subject = str_ireplace($x, '<b>'.$x.'</b>', $subject);
}
echo $subject;
The string functions are much faster then the regular expression engine.
If you do use regex, the PCRE functions are faster.
http://www.php.net/preg_replace
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
Offline 1,250 posts
since Sep 2005