note 103698 added to language.types.string
| From: | Ultimater at gmail dot com | Date: | Thu, 28 Apr 2011 18:07:47 +0000 |
| Subject: | note 103698 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179244@lists.php.net to get a copy of this message | ||
Jeff's code, for evaluating php expressions within strings, contains errors (a misusage of eval
and a missing = character) but the concept is good -- thanks for that. Here is a corrected version
that should get the job done:
<?php
//Ultimater at gmail dot com's revision of jeff at kingdesk dot com's code
$eval='evaluate';
function evaluate($str)
{
return eval("return $str;");
}
echo "2 + 2 = {$eval('2+2')}";
?>
Note that I renamed the function to $eval rather than the desperate looking $e->val.
----
Server IP: 69.147.83.197
Probable Submitter: 76.90.130.197
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/103698
Del: integrated -- https://master.php.net/note/delete/103698/integrated
Del: useless -- https://master.php.net/note/delete/103698/useless
Del: bad code -- https://master.php.net/note/delete/103698/bad+code
Del: spam -- https://master.php.net/note/delete/103698/spam
Del: non-english -- https://master.php.net/note/delete/103698/non-english
Del: in docs -- https://master.php.net/note/delete/103698/in+docs
Del: other reasons-- https://master.php.net/note/delete/103698
Reject -- https://master.php.net/note/reject/103698
Search -- https://master.php.net/manage/user-notes.php