note 56671 deleted from function.eval by sniper

From: Date: Thu, 29 Dec 2005 09:16:09 +0000
Subject: note 56671 deleted from function.eval by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100923@lists.php.net to get a copy of this message
Note Submitter: K.Tomono[tom11147 at casio dot co dot jp ---- You can take the part of your php code to outside from your HTML template using the method like a following. <?php declare(encoding="ASCII"); mb_internal_encoding("UTF-8"); mb_regex_encoding(mb_internal_encoding()); ini_set("display_startup_errors","1"); ini_set("display_errors","1"); error_reporting(E_ALL); ob_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <div id="block::replace"></div> </body> </html> <?php $html = ob_get_contents(); ob_end_clean(); $block_replace = '<?php echo $block_replace_val; ?>'; $block_replace_val = 'This is the output by the additional php code generated with ob_* and eregi_replace, eval functions.'; $tc = "[[:alnum:]\\.:_-]"; $sp = "[[:space:]]"; $id = "block::replace"; $html = mb_eregi_replace( "(<{$tc}+{$sp}+[^>]*id{$sp}*={$sp}*\"{$id}\"[^>]*>)", "\\1\n". $block_replace, $html); $html = '?>'. $html . '<?'; ////echo "$html\n"; eval($html); ?> You can do that completely at least when the requirement is simply "echo" like the above code. Actually the scheme is not so simple, I know. There are some other complex logical structures like as "if" (conditional branch), "while" (loop), and so on. However, I think that this is the very useful solution when work sharing is required between a programer and a HTML designer. and I think that it is also possible to implement other logical structures by extension of this method as substitution of the complicated existing template engines. #the regexp pattern should be refined more in real use.

« previous php.notes (#100923) next »