php - Storing a piece of the string for later use in replacement -
It is not certain that the subject was clear, it is difficult to describe, easy to show:
It needs change:
$ text = '% textgroup% img_green% img_Red and some more text here';
To do this:
$ text = 'bunch of text & lt; Img src = "/ assets / images / green.gif" alt = "green" / & gt; & Lt; Img src = "/ assets / images / Red.gif" alt = "red" /> And some more text here ';
Thanks in advance.
$ text = preg_replace ('/% img _ (\ W +) / ',' & lt; img src = "/ assets / images / \ 1.jpg" alt = "\ 1" /> ", $ text);
Check how it's working
Comments
Post a Comment