#1 蔓荆子_金刚电商
class jiexi extends spController {
//按DW 的 input 顺序修改模版中的input顺序 ,
//格式为
//如果模版中属性没有则自动为空,不会修改其他任何数据,只改变input 控件属性显示位置
function index() {
//模版路径 绝对路径
$dir = APP_PATH . 'template/admin';
$this->getFile($dir);
}function jiexi($template) {
$ary_1 = array();
//正则
$match_1 = preg_match_all('//is', $template, $ary_1);
if ($match_1 > 0) {
for ($i = 0; $i < $match_1; $i++) {
//$ary_1[1][$i] 为input的属性值和 name="typeid" type="hidden" value="<{$typeid}>"
$ary_2 = array();
preg_match_all('/(.+?)="(.+?)"/is', $ary_1[1][$i], $ary_2);
//去除键名空格
$ary_2_1 = array();
foreach ($ary_2[1] as $v) {
$ary_2_1[] = trim($v);
}
//去除键值空格
$ary_2_2 = array();
foreach ($ary_2[2] as $v) {
$ary_2_2[] = trim($v);
}
//合并数组
$ary_2_3 = array_combine($ary_2_1, $ary_2_2);
//input 属性数组
$ary_att = array('name', 'type', 'disabled', 'class', 'id', 'title', 'onblur', 'onclick', 'value', 'size', 'maxlength', 'minlength', 'readonly');
//循环属性数组 有则加入input组合中
$zuhe = '';
foreach ($ary_att as $v) {
if (array_key_exists($v, $ary_2_3)) {
$zuhe .= ' ' . $v . '="' . $ary_2_3[$v] . '"';//按顺序组合input
}
}
$zuhe = '';
$template = str_replace($ary_1[0][$i], $zuhe, $template);//替换原来的不规则input
}
}
return $template;
}//获取文件目录列表,该方法返回数组
function getDir($dir) {
$dirArray[] = NULL;
if (false != ($handle = opendir($dir))) {
$i = 0;
while (false !== ($file = readdir($handle))) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".." && !strpos($file, ".")) {
$dirArray[$i] = $file;
$i++;
}
}
//关闭句柄
closedir($handle);
}
return $dirArray;
}//获取文件列表
function getFile($dir) {
if (false != ($handle = opendir($dir))) {
//$i = 0;
while (false !== ($file = readdir($handle))) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".." && strpos($file, ".")) {
//模版文件路径 可以直接改为自己的模版路径
$data = file_get_contents(APP_PATH . 'template/admin/' . $file);
//写入的新文件路径 目录先建立好
file_put_contents(APP_PATH . 'template/test/' . $file, $this->jiexi($data));
}
}
//关闭句柄
closedir($handle);
}
exit('ok');
}}
2012-10-23 21:29:19