views:

40

answers:

2

In PHP my string looks like this: "{{edit(3)}}".
I would like the result to be: "open3close", using preg_replace or another method.

Any ideas?

+2  A: 

Escape { and } to \{ and \} in regex string

S.Mark
i guess it, but something is going wrong, may you suggest me an example?
TrustWeb
@TrustWeb, for example, `preg_replace('/\{\{(.*?)\}\}/',"open3close",$text);`
S.Mark
only ( and ) need to be escaped. thanks :)
TrustWeb
+1  A: 

I'm sorry if you wasted your time, i found a valid solution.

preg_replace("/{{edit((.*))}}/e","'open'.'\\1'.'close'", $string);

input : {{edit(3)}} output: open3close

TrustWeb