2013-10-07 27 views
0

我有这个字符串:
的preg_replace [{和}]

$string='My String [{Text_001}] My String [{Text_002}] ';

我想用的preg_replace [{事}]由$的东西(如更换:[{Text_001}] - > $ Text_001 )。

我有我的preg_replace错误:

$string = preg_replace('/([{.+?)+(}])/i', "$1", $string);

回答

0
$string = preg_replace('~\[\{(.+?)\}\]~', "\$$1", $string); 
# My String $Text_001 My String $Text_002 

Explanation example

0

用途:

<?php 
$string='My String [{Text_001}] My String [{Text_002}] '; 

$string = preg_replace("~".preg_quote('[{')."(.*?)".preg_quote('}]')."~","something", $string); 

echo $string; 
?> 

输出更换后[{something}]通过something

My String something My String something