Re: Display Variable within a variable
| From: | Miles Thompson | Date: | Thu, 04 Jan 2001 04:00:18 +0000 |
| Subject: | Re: Display Variable within a variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32604@lists.php.net to get a copy of this message | ||
Christopher,
BINGO! (I've got to spend some time on regular expressions and replacement and evaluation functions.)
Thanks very much - Miles Thompson
At 11:27 AM 01/03/2001 -0600, you wrote:
If I understand you correctly (I probably don't), you're just looking for way to interpolate (fill in) a variable within a string that you get from your database (thus being a variable itself). If that's so, I always do a preg_replace( ... ) with the eval option '//e'. Example say you fetched this msg from your database and shoved it into a variable called $template, and it looks like this:$template = "Thank you for your bid. To be accepted it must increase the previous bid by $yMinBidIncr. Please adjust the amount and send it again." $yMinBidIncr is the amount by which this bid must exceed the previous bid. replace the $yMinBidIncr with '{yMinBidIncr}' (without the qoutes) in your database andrun this on it. $yMinBidIncr = 19.99; $template = preg_replace( '/\{([^}]*)\}/e', '$\\1', $template ); and now $template will contain:"Thank you for your bid. To be accepted it must increase the previous bid by 19.99. Please adjust the amount and send it again." $yMinBidIncr is the amount by which this bid must exceed the previous bid. all that preg_replace does is search for things like {whatever} and replaces it with a $whatever and then evals it.Hope this helps you out. _chris thepope@emphasys.net