note 51864 added to function.create-function
| From: | david | Date: | Wed, 13 Apr 2005 09:15:25 +0000 |
| Subject: | note 51864 added to function.create-function | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87944@lists.php.net to get a copy of this message | ||
# dynamically create html helper functions which take the args
# $string_contents, $optional_hash_of_options
# and return the contents wrapped in a tag
$html_funcs = Array(
'table',
'tr',
'th',
'td',
'div',
'span',
'pre',
'strong',
'em'
);
$args = '$html, $options=Array()';
$code = '
$o = "";
foreach ($options as $a => $b) {
$o .= " $a=\"$b\"";
}
return "<$tag$o>$html</$tag>";
';
foreach ($html_funcs as $key => $tag) {
${$tag} = create_function($args, "\$tag = '$tag'; $code");
}
# usage example:
print $table(
$tr($th('heading').$td('this is the cell content')),
Array('style'=>'border: 1px solid silver;')
);
----
Manual Page -- http://www.php.net/manual/en/function.create-function.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51864
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51864&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51864&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51864&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51864&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51864&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51864&report=yes
Search -- http://master.php.net/manage/user-notes.php