Re: Re: Execute statements from a string???
| From: | Shawn McKenzie | Date: | Tue, 22 Oct 2002 16:06:42 +0000 |
| Subject: | Re: Re: Execute statements from a string??? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120935@lists.php.net to get a copy of this message | ||
One last thing...
The way I currently evaluate the commands is with a switch, example:
switch ($command[$i]); {
case "[query-results]":
if($something) {
some_func(); }
break;
case "[some-command]":
some_other_func();
break;
}
But to make it simpler I would like to define a command, $command[] and the
actual instructions for the command, $dowhat[].
$command[1] = "[query-results]";
$dowhat[1] = "if($something) { some_func(); }";
And then when I find $command[1] eval() the $dowhat[1] string.
Making sense???
Thanks!
-Shawn
"Shawn McKenzie" <nospam@mckenzies.net> wrote in message
news:20021022155541.83895.qmail@pb1.pair.com...
> Abridged version of my story :-)
>
> To keep web designers out of the coding business I wrote a little script
> similar to a template engine but far simpler.
>
> How it works:
>
> -I read an HTML file into a string
> -I parse the string and echo until I reach a HTML comment <!-
> -I then search the comment for a defined "command" such as [query-results]
> -I then execute some PHP depending on the command
> -Continue parsing...
>
> This works great, but... What if someone wants to include actual PHP code
in
> the HTML file???
>
> Hence my question.
>
> Thanks!
> Shawn
>
>
> "Maxim Maletsky" <maxim@php.net> wrote in message
> news:20021022165924.4E01.MAXIM@php.net...
> >
> > "Shawn McKenzie" <nospam@mckenzies.net> wrote... :
> >
> > > Thanks for the answers!
> > >
> > > Next question. How can I structure the string and how do I echo the
HTML
> and
> > > the variable contents? I want the following output to the browser:
> > > <td>Hello...</td>
> > >
> > > $somevar = "Hello...";
> > >
> > > $string = "<td><?php echo $somevar ?></td>\n";
> > > or
> > > $string = "<td>$somevar</td>\n";
> > >
> > > eval() ???
> >
> >
> > let's say: you get *any* PHP code and stick it within eval('code') so,
> > then it gets executed. But, why on the earth do you need it?
> >
> > Tell us your story, from begining to the end :)
> >
> >
> > ---
> > Maxim Maletsky
> > maxim@php.net
> >
> >
> > www.PHPBeginner.com // PHP for Beginners
> > www.maxim.cx // my Home
> >
> > // my Wish List: ( Get me something! )
> > http://www.amazon.com/exec/obidos/registry/2IXE7SMI5EDI3
> >
>
>