0

次のような文字列があります。

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


ここで次のよう{{smartpro=img:hippo-1.jpg,alt:abc,ht:217,wd:247,align:left}}
に置き換えます。
<img src="www.abc.com/media/images/hippo-1.jpg" alt="" width="247" height="217" align="left">
したがって、最終的な文字列は次のようになります。

juices vegetables including <img src="www.abc.com/media/images/hippo-1.jpg" alt="abc" width="247" height="217" align="left"> wheatgrass, leafy greens, parsley, aloe vera & other herbs

助けてください 。
私の試み:preg_replace('~\{{\{{(.+)\:(.+)\}}\}}~iUs','<img src="$2">$1/>',$string);

4

2 に答える 2

1
$string = 'juices vegetables including {{smartpro=img:hippo-1.jpg,alt:Hippocrates,ht:217,wd:247,align:left}} wheatgrass, leafy greens, parsley, aloe vera & other herbs';
$pattern = '/(?:{{smartpro=img:)([^,]+)(?:,alt:)([^,]+)(?:,ht:)([^,]+)(?:,wd:)([^,]+)(?:,align:)([^}]+)(?:}})/i';
$replacement = '<img src="$1" alt="$2" height="$3px" width="$4px" align="$5"/>';
echo preg_replace($pattern, $replacement, $string);
于 2013-09-12T10:17:21.487 に答える