Performing regular expression matches in string of text (HTML), where each match is replaced by the value of an array.
In code it would read something like (I did not test the code, it's just there for illustration purposes
Code: Select all
$my_arr=array('text1','text2,'text3');
$html_string="blablablablabla_blah_bla_blah_blabla_blah_";
//match against "_blah_" not "bla"
$reg_exp="/_blah_/";blablablablablatext1blatext2blablatext3 <- results from array
instead of
blablablablablatext1blatext1blablatext1 <- the first match all the way
I've read about preg_replace_callback, but I can't get the array fed into the callback. Which is the solution I guess...
Is there a way, not to complicated,...