Re: sprintf and arrays.

From: Date: Thu, 07 Apr 2005 09:29:40 +0000
Subject: Re: sprintf and arrays.
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-212516@lists.php.net to get a copy of this message
On Wednesday 06 April 2005 18:05, Brent Baisley typed: > You want to have sprintf look at the contents of the variable instead > of the variable itself. Anytime you want to do something like this you > use the eval() function to evaluate the contents of the variable. Woot! $begin_string = 'htmlentities(sprintf($tmp[0],'; foreach ($p_sub_values as $k => $v) { $mid_string[] = "\$p_sub_values[$k]"; } $mid_string = join(',', $mid_string); $end_string = '), ENT_QUOTES);'; // Eval will stick the three strings together and then execute them. Neat trick, hint from // brent@landover.com. eval ("\$r = $begin_string$mid_string$end_string"); Works a treat. Thanks Brent. -- My mind not only wanders, it sometimes leaves completely.

« previous php.general (#212516) next »