PHP basic questions for help!!!!!!

Source: Internet
Author: User
Here's the thing: I'm querying the MySQL database except for a record that contains variables such as {$aaa}, {$bbb},
Now I want to assign the two variables before the output, but the result of the output is the 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}, long time no see, I was thinking of you {$bbb}! ///////

$AAA = "Andy Lau";
$BBB = "Lin Xin";

echo $row _rs_sql[' content ';
I want the result is: Hello Andy Lau, long time no see, I want your Lin heart like!

But now the result of the output is still: Hello {$aaa}, long time no see, I was thinking of you {$bbb}!

I ask you how to solve this problem ah, very urgent!!!



Reply to discussion (solution)

echo "$row _rs_sql[' content ']";

echo preg_replace ('/\{\$ (\w+) \}/e ', ' $$1 ', $row _rs_sql[' content ');

Here's the thing: I'm querying the MySQL database except for a record that contains variables such as {$aaa}, {$bbb},
Now I want to assign the two variables before the output, but the result of the output is the 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}, long time no see, I was thinking of you {$bbb}! ///////

$AAA = "Andy Lau";
$BBB = "Lin Xin";

echo $row _rs_sql[' content ';
I want the result is: Hello Andy Lau, long time no see, I want your Lin heart like!

But now the result of the output is still: Hello {$aaa}, long time no see, I was thinking of you {$bbb}!

I ask you how to solve this problem ah, very urgent!!!
The Content field is: Hello {$aaa}, long time no see, I was thinking of you {$bbb}! The $aaa inside you is a string, not 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 PHP eval () function http://php.net/manual/en/function.eval.php

$str = $row _rs_sql[' content '];eval ("\ $str = \" $str \ ";"); Echo $str;

The four-storey method is the simplest and most practical.

  • Related Article

    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.