Php 预替换到嵌套字符串

Php 预替换到嵌套字符串,php,preg-replace,Php,Preg Replace,在PHP中,我有一组字符串,如 'various text code(01) various text' 我想把它们变成 'various text <img src="images/code(01).png"> various text' “各种文本各种文本” “code(XX)”可以包含任何数字,如“code(99)”或“code(27)”等,我希望保留该数字并将其嵌套到标记中 我可以使用preg_replace来实现这一点吗? 非常感谢。$str='各种文本代码(01)各

在PHP中,我有一组字符串,如

'various text code(01) various text'
我想把它们变成

'various text <img src="images/code(01).png"> various text'
“各种文本各种文本”
“code(XX)”可以包含任何数字,如“code(99)”或“code(27)”等,我希望保留该数字并将其嵌套到标记中

我可以使用preg_replace来实现这一点吗? 非常感谢。

$str='各种文本代码(01)各种文本';
$str = 'various text code(01) various text';
$str = preg_replace('/code\(\d+\)/', '<img src="images/$0.png">', $str);
print($str);
$str=preg\u replace('/code\(\d+\)/',''$str); 印刷品($str);
演示:

$0
优于
\0
。非常感谢。工作完美。