Why when outputting text, for example, " $value
" from the MySQL base, echo
displays stupid text " $value
", and not its value expressed in the above code "$ value = '1'"?
After all, in fact, it should write 1 instead of $value
...
Why when outputting text, for example, " $value
" from the MySQL base, echo
displays stupid text " $value
", and not its value expressed in the above code "$ value = '1'"?
After all, in fact, it should write 1 instead of $value
...
PHP doesn't owe you anything.
The substitution of variable values into a string ( interpolation ) occurs only if you explicitly define this string in code. If you get a string from somewhere else (database, text file, environment variables, etc.), then no interpolation occurs. The string remains as it is.
What to do with it?
You can try to interpret the string as PHP code, but this is a very bad idea. Here is an example:
// $template содержит строку 'echo $value;' eval($template);
The only problem is that the $template
line must contain valid PHP code. Well, this is a very big potential vulnerability.
You can try to use regular expressions to replace variables with their values, which is also rather sad.
More correctly, it would be to use some placeholders for variables and dynamically generate a result based on the context. In general terms, it might look something like this:
$template = '{{value}}'; $context = ['value' => 1]; // Выведет "1". echo render($template, $context);
In the example above, the render
function is an abstract line processor. And yes, this is how template templates work.
From the question is not clear. Here is a simple example of output.
$value = 1; echo '$value'; // выдаст $value т.к воспринимается не как переменная а как символы echo "$value"; // выдаст 1 т.к это подобие кантотанации echo $value; // выдаст 1 просто вывод переменной
This is from what I understood. If the error is that you have in the database the variable name as $ value then this is a string and there is nothing understandable here.
Here you can find more details .
Respect the time of people who want to help you solve your problem follow the rules
Source: https://ru.stackoverflow.com/questions/507765/
All Articles