Preg_replace in php - multiple replace -
i have $string, contains:
this example
and have these 3 expressions:
$pattern = array('/aa*/','/ii*/'); $replacement = array('<i>$0</i>','<b>$0</b>'); preg_replace($pattern, $replacement, $string);
where, preg_replace returns:
th<b>i</b>s ex<<b>i</b>>a</<b>i</b>>mple
and need output this:
th<b>i</b>s ex<i>a</i>mple
which means, want replace characters in original string. possible?
this trick in testing
$pattern = array('/([a-z|^|\s])(aa*)/', '/([a-z|^|\s])(ii*)/'); $replacement = array('$1<i>$2</i>','$1<b>$2</b>');
Comments
Post a Comment