views:

42

answers:

1

Not sure if the subject was clear, hard to describe, easy to show:

I need to convert this:

$text = 'Bunch of text %img_Green %img_Red and some more text here';

to this:

$text = 'Bunch of text <img src="/assets/images/Green.gif" alt="Green" /> <img src="/assets/images/Red.gif" alt="Red" /> and some more text here';

Thanks in advance.

+3  A: 

should be

$text = preg_replace('/%img_(\w+)/', '<img src="/assets/images/\1.jpg" alt="\1"/>', $text);

check out the preg_replace doc page on how this is working

Justin
Worked a treat. Thanks Justin!
k00k