Suppose there are 3 keywords,
I don't want to do this kind of replace 3 times:
a => <b>a</b>
str_replace ( 'a', '<b>a</b>', $str)
Is it possible to do it by one run?
Suppose there are 3 keywords,
I don't want to do this kind of replace 3 times:
a => <b>a</b>
str_replace ( 'a', '<b>a</b>', $str)
Is it possible to do it by one run?
You can use the strtr (or mb_strtr) function in PHP
$trans = array("hello" => "hi", "said" => "screamed");
echo strtr("hi all, I said hello", $trans); // prints out "hi all, I screamed hi"
Use preg_replace()
with a backreference:
$text = "foo bar baz";
echo preg_replace('/(a)/', '<b>$1</b>', $text);
preg_replace('/(a|e|i|o|u)/', '<b>$1</b>', $string);
have you considered looking into <b>
vs <strong>
?