There is some variable $var equal for example 123. I want to get its value in this form: ${123} . String, but in curly braces and with the dollar. How can I do it? If you escape all "obscure" characters like this "\$\{$var\}" then it is not that $\{123\} . You can of course use sprintf instead of string interpolation ...

  • Duck dollar only screen, brackets, then why? or concatenation use - teran
  • @teran if I do not escape the brackets, then they disappear. Those. it turns out just $123 . - PECHAPTER
  • one
    double bracket then - teran
  • @teran and this is already true. Thanks It works! - PECHAPTER

1 answer 1

Refer to the documentation for the strings: http://php.net/manual/ru/language.types.string.php

  • to escape a dollar sign, use \$
  • then write two curly braces {{ and }} . The first and last parentheses will simply be displayed as characters, but the inner ones will be related to the subsequent variable, that is, {$var} . In fact, there is no shielding here, just nested brackets are considered along with the variable that is enclosed in them.

As you have already written, options are possible using sprintf or the concatenation of '${'.$var.'}'