开发者

printing $variable from mysql result

开发者 https://www.devze.com 2023-03-17 07:16 出处:网络
I have a mysql binary table that I am storing html email layout. In this layout I want to put tags that are populated in the page that the layout will be called in. I can\'t seem to get it to display

I have a mysql binary table that I am storing html email layout. In this layout I want to put tags that are populated in the page that the layout will be called in. I can't seem to get it to display anything but the tags.

Example:

called from mysql database ->

 $sql_result = 'The property name is $prop_name.';

 $message = <<<EOF
 $sql_result
 EOF;

When I load the page it will email the result with $prop_name instead of the actual name that is defined earlier in the scripting. The display on the page its works for the pre-defined $prop_name variable but the emailed part does not display it. Even when I echo or print the result on the same page it will just put the 开发者_StackOverflow中文版$prop_name instead of the earlier defined call. How do I get the variable to show the pre-defined defintion for it when I call it from a database?


If you pull "The property name is $prop_name." out of the database, that is just pure text. It will not change the $prop_name with your $prop_name variable.

What you should do is simply replace the text.

Thus:

$prop_name = "Finca el Otero";
$output = str_replace('$prop_name', $prop_name, $sql_result);
echo $output;

This will replace the $prop_name anchor in your text (as in your $sql_result variable) with the content of your $prop_name variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号