note 39050 added to function.eval
| From: | xlex at rn2 dot php dot net | Date: | Thu, 15 Jan 2004 14:07:31 +0000 |
| Subject: | note 39050 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63608@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39050
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39050&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39050&report=yes
Search -- http://master.php.net/manage/user-notes.php