Re: Re: Execute statements from a string???

From: Date: Tue, 22 Oct 2002 17:10:00 +0000
Subject: Re: Re: Execute statements from a string???
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-120951@lists.php.net to get a copy of this message
I agree... I was asking about eval() because it was an answer earlier in the thread. Question #1: What I really want to do as it pertains to the HTML file in the string is to echo <td>Hello...</td> using a string containing HTML and PHP. Using: $somevar = "Hello..."; $string = "<td><?php echo $somevar ?></td>\n"; //example, I actually read an html file into here echo $string; What I get is <td></td> Using: $string = "<td>$somevar</td>\n"; //example, I actually read an html file into here echo $string; What I get is <td>$somevar</td> Question #2: My other post about the commands I was hoping to put my commands and their related statements into an array, loop through testing for $command[] and when found execute $dowhat[]. Any better ideas are on either issue is very welcome and much appreciated! Thanks! Shawn "Maxim Maletsky" <maxim@php.net> wrote in message news:20021022182830.4E13.MAXIM@php.net... > > What is the need of using the eval() for this? Can't you just do it in > plain PHP? You are reinventing the wheel, complicating your life, Shawn. > > > --- > 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 > > > > "Shawn McKenzie" <nospam@mckenzies.net> wrote... : > > > 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 > > > > > > > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > >

« previous php.general (#120951) next »