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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -