Re: Recursive Interpolation

From: Date: Tue, 05 Oct 2004 03:52:13 +0000
Subject: Re: Recursive Interpolation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198643@lists.php.net to get a copy of this message
On Mon, 4 Oct 2004, Chuck Wolber wrote: > Database *FIELD* with text data in it. The text data contains sentences > interspersed with $foo['bar'] array variables. The idea is that when one > selects this field, PHP will interpolate $foo['bar'] with the currently > defined $foo array variable. This allows for "form letter" like > dispatches to be created. The method I've come up with in the meantime, I believe is much more effective than heredocs, but still an ugly hack: function interpolate ($text, $msg_variable) { $msg_key = '_FP_VAR_'; foreach (array_keys($msg_variable) as $key) { $token = $msg_key.$key; $text = preg_replace("/$token/", "$msg_variable[$key]", $text); } return ($text); } -- http://www.quantumlinux.com Quantum Linux Laboratories, LLC. ACCELERATING Business with Open Technology "The measure of the restoration lies in the extent to which we apply social values more noble than mere monetary profit." - FDR

« previous php.general (#198643) next »