regex - Find a inner text between 2 symbols and replace inner text using regular expressions in php -
i've been googling , trying myself can't , headache. have string:
"estamos en el registro {id} cuyo contenido es {contenido} por lo que veremos su {foto}" i need replace {value} $value getting string this
"estamos en el registro $id cuyo contenido es $contenido por lo que veremos su $foto" it posibble using regular expressions in php
thanks in advance answer
do this:
$replaced = preg_replace('~{([^}]*)}~', '$$1', $yourstring); on the demo, see substitutions @ bottom.
{matches opening brace}matches closing brace- in
([^}]*), parentheses captures group 1[^}]*...[^}]negative character class means 1 char not closing brace, ,*quantifier means 0 or more times $$1replaces match literal$, content of capture group ($1)
Comments
Post a Comment