Thursday, 12 September 2013

Replace a pattern string to a structured string

Replace a pattern string to a structured string

I have a string like :

juices vegetables including
{{smartpro=img:hippo-1.jpg,alt:Hippocrates,ht:217,wd:247,align:left}}
wheatgrass, leafy greens, parsley, aloe vera & other herbs

Now here
{{smartpro=img:hippo-1.jpg,alt:Hippocrates,ht:217,wd:247,align:left}}
replace with
<img src="www.abc.com/media/images/hippo-1.jpg" alt="" width="247"
height="217" align="left">
So the final string will be :

juices vegetables including <img
src="www.abc.com/media/images/hippo-1.jpg" alt="" width="247" height="217"
align="left"> wheatgrass, leafy greens, parsley, aloe vera & other herbs
Please help .
My attempt : preg_replace('~\{{\{{(.+)\:(.+)\}}\}}~iUs','<img
src="$2">$1/>',$string);

No comments:

Post a Comment