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

From: Date: Wed, 23 Oct 2002 05:03:04 +0000
Subject: Re: Re: Execute statements from a string???
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-121033@lists.php.net to get a copy of this message
Yes. I have a lot of extraction and manipulation of the HTML before I echo it to the browser. I got this to work, sort of: $string = "?> ".$string; eval($string); But this causes parse errors later in my script. I tried this: $string = "?> ".$string>" <?php"; But that causes even more issues. Thanks! Shawn "David Robley" <robleyd@paradise.net.nz> wrote in message news:MPG.1820e547f0e98bae9897bb@news.php.net... > In article <20021022170944.56502.qmail@pb1.pair.com>, nospam@mckenzies.net > says... > > 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 :) > > Any reason you can't just include() the html file? > > -- > David Robley > > A: Because it messes up the order in which people normally read text. > Q: Why is top-posting such a bad thing? > A: Top-posting. > Q: What is the most annoying thing on usenet?

« previous php.general (#121033) next »