note 56671 added to function.eval
| From: | K.Tomono | Date: | Mon, 12 Sep 2005 05:56:20 +0000 |
| Subject: | note 56671 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95032@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56671
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56671&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56671&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56671&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56671&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56671&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56671&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56671&report=yes
Search -- http://master.php.net/manage/user-notes.php