The variable replacement method in the string. I want to replace the variable in the string, for example:
$ A = "12345 ";
Echo "a = $ a"; a = 12345 is printed;
This is the result I want. But now there is a problem, that is, I put the string a = $ a in the database and then extract it. what the same statement prints out is
A = $ a. What should I do if I still want to achieve the above effect?
Reply to discussion (solution)
I checked it and said that php only processes parsing in double quotation mark strings. that is to say, what I get from the database is not necessarily treated as a string, right?
"A =". $ a; so?
"A =". $ a; so?
The key is that $ a is treated as "$ a" instead of a php variable.
Why do we need to store variables in the database? your example shows that the value of Directly storing the field is 12345, and echo $ a ['A']; is not better.
Why do we need to store variables in the database? your example shows that the value of Directly storing the field is 12345, and echo $ a ['A']; is not better.
In this case, the reason why I need to make an adaptive program in the database is that I need to store the function name and parameters in the database, and I can use it in the database, for example, if I have a function that calls func ($ B) and $ B is a variable, the value of this variable is "a = $ a", that is, to pass in such a string, $ a is a variable and can be set to any value. The function name func is saved in my database. the parameter a = $ a is combined into fun ("a = $.
This is okay. my problem is that I write the string a = $ a to the database, and then I can't identify $ a as a variable and use it as a string.
Use Eval.
$ Str = 12345;
Eval ("\ $ s = \" a = $ str \";");
Echo $ s;
Use Eval.
Thank you so much! you have saved me!
$ Str = 12345;
Eval ("\ $ s = \" a = $ str \";");
Echo $ s;
I just saw it. why don't you give me 10 points.