可以在 PHP 中用文本替换表达式


Is possible to replace an expression with a text in PHP?

例如,可以替换

{'a1b2,left'}

<img src="a1b2" class="left"/>

在菲律宾?

是的...

$str = preg_replace('/'{''(.*?),(.*?)'''}/', '<img src="$1" class="$2"/>', $str);

是的,你可以。

//strip unwanted characters.
$string = preg_replace("/[{'}]/", "", $string);
//convert string to array
$string = explode(',', $string); 
<img src="<?php echo $string[0]; ?>" class="<?php echo $string[1]; ?>"/>