note 39050 deleted from function.eval by didou

From: Date: Thu, 15 Jan 2004 14:13:05 +0000
Subject: note 39050 deleted from function.eval by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63609@lists.php.net to get a copy of this message
Note Submitter: xlex(_AT~)fromru(~DOT-)com ---- Not sure about others, but I spend lot of time to solve the following problem: I have some, for example, translation data (f.e.: $lang['Message'] = "Hello, $User!";) and I'd like to replace variable '$User' with it's actual value (f.e.: 'Vasya Pupkin') and get hall translation string back with replaced variable (f.e.: $lang['Message'] = "Hello, Vasya Pupkin!";). So, at the end of all this I wrore function, that fix 'eval()'s unability to return evaluated string. So, that is: ================================== <?php function evaluate ($Source = NULL) { eval("\$Output = \"".addslashes($Source)."\";"); return $Output; } ?> ================================== Example: <?php $User = 'Vasya Pupkin'; $lang['Message'] = "Hello, $User!"; $Result = evaluate($lang['Message']); ?> will print 'Hello, Vasya Pupkin!'. Hope, this will help someone... /Alexandre.

« previous php.notes (#63609) next »