A
Anonymous
Guest
Hi guys and gals...I'm relatively new to this PHP stuff, so bear with me...
Anyway, here's the question: Is it possible to call a function inside of a string?
Here's the scenario: I created a function named "list_products_and_quantities()", which I wanted to call upon at a certain point inside the body of a PHP-server-generated email.....I set the function equal to a variable $list, and attempted to display $list (and subsequently execute "list_products_and_quantities()") inside the email message string....I know you can display values of variables inside strings, so I was hoping that if I set the value of $list equal to a function, then $list would call the associated function...but it's not working....any ideas? Maybe there is another way to do this besides employing a function inside of a string?
If you're interested, here is the portion of the code you need to be concerned with:
<?php
function list_products_and_quantities()
{
for ($n=1; $n<=3; $n++)
if (!trim($product_code[n]))
$n = $n;
else
echo "
- $quantity[n] blue widget(s) (product code: $product_code[n])";
}
$list = list_products_and_quantities();
mail($mail_to,
$subject,
"
Thank you, $first_name, for your recent purchase from Media Moguls.
Our records indicate that you made the following purchase(s): $list
\$000.00 will be billed to your $payment_method credit card.
We have the following billing information for you:
Address: $address
Suite #: $suite
City: $city
State: $state
ZIP: $zip
We have the following shipping information for you:
Address: $address2
Suite #: $suite2
City: $city2
State: $state2
ZIP: $zip2
If any of this information is incorrect, please contact us immediately via the Media Moguls web site. Do not reply to this confirmation email. Replies will not be answered.
We recommend that you save or print this confirmation email for your records. This email functions as your receipt of purchase.
Thank you for shopping with Media Moguls. Please visit us again!
\t - The Media Moguls team");
?>
Anyway, here's the question: Is it possible to call a function inside of a string?
Here's the scenario: I created a function named "list_products_and_quantities()", which I wanted to call upon at a certain point inside the body of a PHP-server-generated email.....I set the function equal to a variable $list, and attempted to display $list (and subsequently execute "list_products_and_quantities()") inside the email message string....I know you can display values of variables inside strings, so I was hoping that if I set the value of $list equal to a function, then $list would call the associated function...but it's not working....any ideas? Maybe there is another way to do this besides employing a function inside of a string?
If you're interested, here is the portion of the code you need to be concerned with:
<?php
function list_products_and_quantities()
{
for ($n=1; $n<=3; $n++)
if (!trim($product_code[n]))
$n = $n;
else
echo "
- $quantity[n] blue widget(s) (product code: $product_code[n])";
}
$list = list_products_and_quantities();
mail($mail_to,
$subject,
"
Thank you, $first_name, for your recent purchase from Media Moguls.
Our records indicate that you made the following purchase(s): $list
\$000.00 will be billed to your $payment_method credit card.
We have the following billing information for you:
Address: $address
Suite #: $suite
City: $city
State: $state
ZIP: $zip
We have the following shipping information for you:
Address: $address2
Suite #: $suite2
City: $city2
State: $state2
ZIP: $zip2
If any of this information is incorrect, please contact us immediately via the Media Moguls web site. Do not reply to this confirmation email. Replies will not be answered.
We recommend that you save or print this confirmation email for your records. This email functions as your receipt of purchase.
Thank you for shopping with Media Moguls. Please visit us again!
\t - The Media Moguls team");
?>