Basic php questions for help !!!!!! This is the case: I query one record from the mysql database. This record contains variables such as {$ aaa} and {$ bbb,
Now I want to assign values to the two variables before the output, but the output result is still a variable ....
For example:
$ Rs_ SQL = mysql_query ("select content from table where id = '1 '");
$ Row_rs_ SQL = mysql_fetch_array ($ rs_ SQL );
///// The content field is: Hello, {$ aaa}. it's been a long time and I miss you {$ bbb }! ///////
$ Aaa = "Andy Lau ";
$ Bbb = "Lin Xinru ";
Echo $ row_rs_ SQL ['content'];
//// The result I want is: Hello, Andy Lau. I have been missing for a long time!
But the output result is still: Hello, {$ aaa}. it's been a long time to disappear. I want your {$ bbb }!
How can we solve this problem? it's very urgent !!!
Reply to discussion (solution)
Echo "$ row_rs_ SQL ['content']";
Echo preg_replace ('/\{\$ (\ w +) \}/ E',' $ 1', $ row_rs_ SQL ['content']);
This is the case: I query one record from the mysql database. This record contains variables such as {$ aaa} and {$ bbb,
Now I want to assign values to the two variables before the output, but the output result is still a variable ....
For example:
$ Rs_ SQL = mysql_query ("select content from table where id = '1 '");
$ Row_rs_ SQL = mysql_fetch_array ($ rs_ SQL );
///// The content field is: Hello, {$ aaa}. it's been a long time and I miss you {$ bbb }! ///////
$ Aaa = "Andy Lau ";
$ Bbb = "Lin Xinru ";
Echo $ row_rs_ SQL ['content'];
//// The result I want is: Hello, Andy Lau. I have been missing for a long time!
But the output result is still: Hello, {$ aaa}. it's been a long time to disappear. I want your {$ bbb }!
How can we solve this problem? it's very urgent !!!
The content field is: Hello, {$ aaa}. it has been a long time to disappear. I want your {$ bbb }! $ Aaa here is a string, not in the form of a variable, so replace it with $ row_rs_ SQL = str_replace ('{$ aaa}', $ aaa ); $ row_rs_ SQL = str_replace ('{$ bbb}', $ bbb); echo $ row_rs_ SQL;
Do not use str_replace (), refer to the php eval () function http://php.net/manual/en/function.eval.php
$str = $row_rs_sql['content'];eval("\$str = \"$str\";");echo $str;
The method on the fourth floor is the simplest and most practical.