Re: storing function names in db and running them as row is output?

From: Date: Wed, 20 Sep 2006 20:42:53 +0000
Subject: Re: storing function names in db and running them as row is output?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-241993@lists.php.net to get a copy of this message
blackwater dev wrote:
great, thanks. So if it's just text, eval won't do anything? On 9/20/06, Christopher Weldon <cweldon@cerberusonline.com> wrote:
blackwater dev wrote:
First, the example I have is not the real situation, just an example so
I
don't want to get into why are you doing it like that, etc. Just want
to
see if it's possible. Basically, I want to store stuff in a text field in a db like this
"johns
name is ucfirst('john adams') ". When I cycle through that row for output in my php script, I want it to
not
see ucfirst as text but as the php function and run it....how is the possible? Thanks.
$db_query = mysql_query("select command from table"); if ($db_query && mysql_num_rows($db_query) > 0) { while ($array = mysql_fetch_array($db_query)) {
     eval($array['command']);
} } eval() is your solution. -- Christopher Weldon, ZCE President & CEO Cerberus Interactive, Inc. cweldon@cerberusonline.com 979.739.5874
Umm, I believe eval will error out if it's just text. eval is basically processing a PHP command, so if you have something like "Bob Smith" and you run: eval("Bob Smith"); It will error out because "Bob Smith" is not a something that can be processed by PHP. -- Christopher Weldon, ZCE President & CEO Cerberus Interactive, Inc. cweldon@cerberusonline.com 979.739.5874

« previous php.general (#241993) next »