Re: Recursive PHP tag resolution

From: Date: Sat, 06 Oct 2001 09:42:30 +0000
Subject: Re: Recursive PHP tag resolution
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-70211@lists.php.net to get a copy of this message
Not quite. eval() provides the basic capability for what I was saying, but the need to use an explicit function to make the string get processed by PHP means multi-level recursion becomes very complex and programming-specific. For one thing, you have to use the right number of escape characters at each level or it all goes awry. The implementation I was suggesting/asking about replaces the text of each PHP call with any text generated by that call, but does this in the input text stream, so PHP processing continues from the beginning of that new text. This gets rid of the need for the eval() function, escape characters, etc. If generated text contains PHP statements, they are handled seamlessly, without regard to the number of levels. Simple example: initial input stream: <?php $text='My name is <?php echo $name; ?>';$name='John';echo $text; ?> input stream after $text= statement is processed: $name='John';echo $text; ?> input stream after $name= statement is processed: echo $text; ?> input stream after echo statement is processed: My name is <?php echo $name; ?> input stream after embedded echo statement is processed, which is also the resolved text: My name is John This trivial example doesn't illustrate the power of RTR, but it enables elegant solutions to very complex text processing and generating tasks, such as data based web pages where the page structure itself is stored in the database, context sensitive address formatting, and many others. If PHP can't do this yet, I know it would be a great, easy to implement enhancement. John Gunther Bucks vs Bytes Inc Rasmus Lerdorf wrote:
Isn't that just an eval() ?
On Sat, 6 Oct 2001, John Gunther (Bucks vs Bytes Inc) wrote:
I've used recursive text expansion to great advantage in many contexts over the years, and I'd like to ask if there's any way to make this happen in PHP. Recursive token resolution (RTR) can greatly simplify programming logic. With RTR, text generated by, for example, a PHP echo statement, would in turn be processed by PHP as though it were there from the outset. If that newly generated text contained PHP tags and code, their evaluation would affect the resulting page. Here's a trivial example: <?php phpinfo(); echo "<?php phpinfo();?>" ?> If RTR worked in PHP, this code would generate a page of two successive PHPINFO displays, but in reality it doesn't. Is there a technique for doing RTR in PHP, and if not, has the issue been considered and discussed? My searches for mention of this topic have all been unsuccessful. If anyone is interested in hearing more about the benefits, I'd be happy to start a thread in this or another group. Incidentally, if there's a better group for this post, I'd appreciate being told what it is. Thank you.


« previous php.general (#70211) next »