note 46206 added to function.eval
| From: | Dernassi at osu1 dot php dot net | Date: | Sat, 02 Oct 2004 11:00:56 +0000 |
| Subject: | note 46206 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77735@lists.php.net to get a copy of this message | ||
Many asked me some precisions on the way
a caller script should call the function "evaluer.php".
Here is an example with some PHP functions:
*************************************
<?php
function evaluer($chaine)
{
$valeur = '$valeur=' . $chaine;
eval("$valeur");
return ($valeur);
}
?>
#-------------------------------------------
# Example: you must add "require" or "include"
#-------------------------------------------
<?php
include ("evaluer.php");
#****************
$chaine = 'strlen("PHP is powerful");';
$valeur = evaluer($chaine);
echo "valeur=$valeur <br>\n";
$chaine = 'substr("What a wonderful world is PHP",7,8);';
$valeur = evaluer($chaine);
echo "valeur=$valeur <br>\n";
$chaine = 'strpos("What a wonderful world is PHP","wonder");';
$valeur = evaluer($chaine);
echo "valeur=$valeur <br>\n";
?>
This should output the following result directly to the browser:
valeur=15
valeur=wonderfu
valeur=7
NB. Please read the PHP manual before contacting me.
The PHP manual is a good source full of information.
Again thanks to all contributors.
By: M. Dernassi,
lamp@dernassi.com
http://dernassi.com/
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46206
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46206&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46206&report=yes
Search -- http://master.php.net/manage/user-notes.php