最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
写了个函数
时间:2022-07-02 10:06:43 编辑:袖梨 来源:一聚教程网
/**
* 函数 data_box
* 功能 根据模板输出数据源中的内容
* 参数
* $fun 回调函数,必须提供。作用是从数据源中读取数据。要求返回的最好是关联数组
* $source 数据源,必须提供。可以是数组或查询结果
* $template 模板,可以没有。未提供模板时用标准表格输出数据
* 模板格式:
* array(top=>"",block=>"",fool=>"")
* 其中:
* top 开始部分
* block 可重复部分,变量为关联数组的键,形如$IN_varname。其中前导的IN_可省略
* fool 结束部分
*/
function data_box($_fun,$_source,$_template="") {
$_ar = $_fun(&$_source);
if($_template == "") {
while(list($k,) = each($_ar)) {
$th .= "$k ";
$td .= "$IN_$k ";
}
$_template = array(top=>"
");
}else if(! preg_match("/$IN_w+/",$_template[block]))
$_template[block] = preg_replace("/[$](w*)/U","$IN_1",$_template[block]);
$buf = eval("return "$_template[top]";");
do {
extract($_ar, EXTR_PREFIX_ALL, "IN");
$buf .= eval("return "$_template[block]";");
}while($_ar = $_fun(&$_source));
$buf .= eval("return "$_template[fool]";");
return $buf;
}
function get_data($source) {
if(list($k,$v) = each($source))
return $v;
return false;
}
$arr = array(
array(a=>1,b=>2,c=>3,11,12,31),
array(a=>11,b=>12,c=>13,11,12,131)
);
echo data_box("get_data",$arr);
echo data_box("get_data",$arr,array(top=>"列表测试
"));
* 函数 data_box
* 功能 根据模板输出数据源中的内容
* 参数
* $fun 回调函数,必须提供。作用是从数据源中读取数据。要求返回的最好是关联数组
* $source 数据源,必须提供。可以是数组或查询结果
* $template 模板,可以没有。未提供模板时用标准表格输出数据
* 模板格式:
* array(top=>"",block=>"",fool=>"")
* 其中:
* top 开始部分
* block 可重复部分,变量为关联数组的键,形如$IN_varname。其中前导的IN_可省略
* fool 结束部分
*/
function data_box($_fun,$_source,$_template="") {
$_ar = $_fun(&$_source);
if($_template == "") {
while(list($k,) = each($_ar)) {
$th .= "
$td .= "
}
$_template = array(top=>"
}else if(! preg_match("/$IN_w+/",$_template[block]))
$_template[block] = preg_replace("/[$](w*)/U","$IN_1",$_template[block]);
$buf = eval("return "$_template[top]";");
do {
extract($_ar, EXTR_PREFIX_ALL, "IN");
$buf .= eval("return "$_template[block]";");
}while($_ar = $_fun(&$_source));
$buf .= eval("return "$_template[fool]";");
return $buf;
}
function get_data($source) {
if(list($k,$v) = each($source))
return $v;
return false;
}
$arr = array(
array(a=>1,b=>2,c=>3,11,12,31),
array(a=>11,b=>12,c=>13,11,12,131)
);
echo data_box("get_data",$arr);
echo data_box("get_data",$arr,array(top=>"列表测试
"));
相关文章
- 《弓箭传说2》新手玩法介绍 01-16
- 《地下城与勇士:起源》断桥烟雨多买多送活动内容一览 01-16
- 《差不多高手》醉拳龙技能特点分享 01-16
- 《鬼谷八荒》毕方尾羽解除限制道具推荐 01-16
- 《地下城与勇士:起源》阿拉德首次迎新春活动内容一览 01-16
- 《差不多高手》情圣技能特点分享 01-16