写了个函数


<?php
/**
* 函数 data_box
* 功能 根据模板输出数据源中的内容
* 参数
* $fun 回调函数,必须提供。作用是从数据源中读取数据。要求返回的最好是关联数组
* $source 数据源,必须提供。可以是数组或查询结果
* $template 模板,可以没有。未提供模板时用标准表格输出数据
* 模板格式:
* array(top=>"",block=>"",fool=>"")
* 其中:
* top 开始部分
* block 可重复部分,变量为关联数组的键,形如$IN_varname。其中前导的IN_可省略
* fool 结束部分
*/
function data_box( 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
fun, 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
source, 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template="") {
写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
ar = 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
fun(& 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
source);
if( 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template == "") {
while(list($k,) = each( 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
ar)) {
$th .= "<th>$k</th>";
$td .= "<td>\$IN_$k</td>";
}
写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template = array(top=>"<table border><tr>$th</tr>",block=>"<tr>$td</tr>",fool=>"</table>");
}else if(! preg_match("/\$IN_\w+/", 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template[block]))
写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template[block] = preg_replace("/[\$](\w*)/U","\$IN_\\1", 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template[block]);

$buf = eval("return \" 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template[top]\";");
do {
extract( 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
ar, EXTR_PREFIX_ALL, "IN");
$buf .= eval("return \" 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
template[block]\";");
}while( 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
ar = 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
fun(& 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
source));
$buf .= eval("return \" 写了个函数
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护
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=>"列表测试<select>",block=>''<option value=$a>$b'',fool=>"</select><br>"));

$tpl = array(top=>"月历测试<table><tr bgcolor=''#000000'' style=''color:#cfcfcf''><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>",block=>''<tr><td>$0</td><td>$1</td><td>$2&l
Copyright © 2008 chengduxinxi.com All Rights Reserved PHP编程开发 由朝夕网络维护