PHP, the variable contains the variable! Php variables
The content of $ mcontent is "dear: {$ user ['username']} your purchased product: {$ goods_name}, Order No. {$ goods_no} has been placed successfully, due to the recent popularity of this product, please pay in time! "
It also contains variables. I can echo $ mcontent; and cannot input any Variables. what can I do !!!
Reply to discussion (solution)
Paste the program segment to see
Strings and variables must be connected.
Try this.
$ Mcontent = "dear :{". $ user ['username']. "} the item you purchased :{". $ goods_name. "}, order number {". $ goods_no. "} the order has been placed successfully. due to the recent popularity of this product, please pay in time! ";
The content is read from the database, but not from the upstairs. you have thought about your method, and you can't read it from the database directly in the code!
$ Query = new IQuery ('MSG _ template'); $ query-> limit = "1"; $ query-> where = "id = 4 "; $ arra = $ query-> find (); $ mtitle = $ arra [0] ['title']; $ mopen = $ arra [0] ['open']; $ mcontent = $ arra [0] ['content']; $ madmin_open = $ arra [0] ['admin _ open']; if ($ madmin_open = 1) {$ madmin_email = $ arra [0] ['admin _ email '];} // $ mcontent = "dear :{". $ user ['username']. "} the item you purchased :{". $ goods_name. "}, order number {". $ goods_no. "} the order has been placed successfully. due to the recent popularity of this product, please pay in time! "; If ($ mopen = 1) {$ smtp = new SendMail (); $ error = $ smtp-> getError (); $ smtp-> send ($ email, $ mtitle, $ mcontent, $ madmin_email );}
$ Content = <
"Dear: {$ user [username]} your purchased item: {$ goods_name}, order number {$ goods_no} has been placed successfully. due to the recent popularity of this product, please pay in time! ";
EOF;
Echo $ content;
Not upstairs !!!!
Not upstairs !!!!
You can output these variables to see what the situation is.
I can't see the source code. I don't even know how the values in your $ mcontent come from ~~~ Only printing can be performed one by one.
// Simulate the data read from the database $ mcontent = <'txt 'dear: {$ user ['username']} your purchased item: {$ goods_name }, order No. {$ goods_no} has been placed successfully. due to the recent popularity of this product, please pay in time! TXT; // the variables involved must be self-secured. $ user ['username'] = 'body'; $ goods_name = 'XXX'; $ goods_no = '2016 '; // solution 1 many people fear eval $ mcontent = eval ("return \" $ mcontent \ ";"); echo $ mcontent; // solution 2 dynamically creates a function, the format is a bit confusing $ f = create_function ('$ user, $ goods_name, $ goods_no', "return \" $ mcontent \";"); $ mcontent = $ f ($ user, $ goods_name, $ goods_no); echo $ mcontent; // or $ f = create_function ('$ user, $ goods_name, $ goods_no ', 'return "'. $ mcontent. '";'); $ mcontent = $ f ($ user, $ goods_name, $ goods_no); echo $ mcontent; // solution 3 template variable replacement, this is an interpreted template engine approach $ mcontent = preg_replace ('/{\$ [^}] +}/E',' $ 1', $ mcontent); echo $ mcontent;Will get:
Dear: body
The product you purchased: xxx, Order No. 123 has been placed successfully. due to the recent popularity of this product, please pay in time!