note 103698 deleted from language.types.string by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Apr 2011 18:30:10 +0000 |
| Subject: | note 103698 deleted from language.types.string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179246@lists.php.net to get a copy of this message | ||
Note Submitter: Ultimater at gmail dot com
----
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.