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
  • $$1 replaces match literal $ , content of capture group ($1)

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -