Basic php questions for help !!!!!!

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.