Home > php教程 > php手册 > 求助:php代码翻译为c#

求助:php代码翻译为c#

WBOY
Release: 2016-06-06 19:40:44
Original
1084 people have browsed it

public function parse_form($template,$fields=0) { //$preg = "/(img|input|textarea|select).*?(\/select|\/textarea|\/)/s"; /* //正则 radios|checkboxs|select js 匹配的边界 |--| 因为当使用 {} 时js报错 php 要保持一致,也使用 |--| 也可以是直接 {

public function parse_form($template,$fields=0)
{

//$preg = "/||\/>)/s";
/*
//正则 radios|checkboxs|select
js 匹配的边界 |--| 因为当使用 {} 时js报错
php 要保持一致,也使用 |--| 也可以是直接 {|- -|}
*/
$preg = "/(\|-(.*?)-\||||\/>))/s";
//获取属性 修改为可变 的匹配
$preg_attr ="/(\w+)=\"(.?|.+?)\"/s";
//获取单选组复选
$preg_group ="//s";
$template_parse =$template;
preg_match_all($preg,$template,$temparr);

$template_data = $add_fields = array();
$checkboxs =0;
if($temparr)
{
foreach($temparr[0] as $pno=>$plugin)
{

$tag = empty($temparr[6][$pno]) ? $temparr[4][$pno] : $temparr[6][$pno];

$attr_arr_all = array();
$name = $leipiplugins = $select_dot = '';
$is_new=false;


if(in_array($tag,array('radios','checkboxs')))//这两个在下面也要//清空边界
{

$plugin = $temparr[2][$pno];

}else if($tag =='select')
{
$plugin = str_replace(array('|-','-|'),'',$plugin);//清空边界
}

 

preg_match_all($preg_attr,$plugin,$parse_attr);

foreach($parse_attr[1] as $k=>$attr)
{
$attr = trim($attr);
if($attr)
{

$val = $parse_attr[2][$k];
if($attr=='name')
{

if($val=='leipiNewField')
{
$is_new=true;
$fields++;
$val = 'data_'.$fields;
}
$name = $val;
}

if($tag=='select' && $attr=='value')
{
$attr_arr_all[$attr] .= $select_dot . $val;
$select_dot = ',';
}else
{
$attr_arr_all[$attr] = $val;
}
}
}

if($tag =='checkboxs') /*复选组 多个字段 */
{
$plugin = $temparr[0][$pno];
$plugin = str_replace(array('|-','-|'),'',$plugin);//清空边界

$name = 'checkboxs_'.$checkboxs;
$attr_arr_all['parse_name'] = $name;
$attr_arr_all['name'] = '';
$attr_arr_all['value'] = '';
$options = $temparr[5][$pno];
preg_match_all($preg_group,$options,$parse_group);
$dot_name = $dot_value = '';

$attr_arr_all['content'] = '';
foreach($parse_group[0] as $value)
{
preg_match_all($preg_attr,$value,$parse_attr);
$is_new=false;
$option = array();
foreach($parse_attr[1] as $k=>$val)
{
$tmp_val = $parse_attr[2][$k];
if($val=='name')
{

if($tmp_val=='leipiNewField')
{
$is_new=true;
$fields++;
$tmp_val = 'data_'.$fields;
}
$attr_arr_all['name'] .= $dot_name . $tmp_val;
$dot_name = ',';
}else if($val=='value')
{
$attr_arr_all['value'] .= $dot_value . $tmp_val;
$dot_value = ',';
}

$option[$val] = $tmp_val;

}
$attr_arr_all['options'][] = $option;
if($is_new)
{
$add_fields[$option['name']] = array(
'name'=>$option['name'],
'leipiplugins'=>$attr_arr_all['leipiplugins']
);
}
$checked = $option['checked'] ? 'checked="checked"' : '';
$attr_arr_all['content'] .= ''.$option['value'].' ';

}
$attr_arr_all['content'] .= ''; //需要content replace

//parse
$template = self::str_replace_once($plugin,$attr_arr_all['content'],$template);
$template_parse = self::str_replace_once($plugin,'{'.$name.'}',$template_parse);
$template_parse = str_replace(array('{|-','-|}'),'',$template_parse);//清空边界
$template_data[$pno] = $attr_arr_all;
$checkboxs++;


}
else if($name)
{
if($tag =='radios') /*单选组 一个字段*/
{
$plugin = $temparr[0][$pno];
$plugin = str_replace(array('|-','-|'),'',$plugin);//清空边界

$attr_arr_all['value'] = '';
$options = $temparr[5][$pno];
preg_match_all($preg_group,$options,$parse_group);
$dot = '';

$attr_arr_all['content'] = '';
foreach($parse_group[0] as $value)
{
preg_match_all($preg_attr,$value,$parse_attr);
$option = array();
foreach($parse_attr[1] as $k=>$val)
{
if($val=='value')
{
$attr_arr_all['value'] .= $dot . $parse_attr[2][$k];
$dot = ',';
}
$option[$val] = $parse_attr[2][$k];

}
$option['name'] = $attr_arr_all['name'];
$attr_arr_all['options'][] = $option;
$checked = $option['checked'] ? 'checked="checked"' : '';
$attr_arr_all['content'] .=''.$option['value'].' ';

}
$attr_arr_all['content'] .= ''; //需要content replace

}else
{
$attr_arr_all['content'] = $is_new ? str_replace('leipiNewField',$name,$plugin) : $plugin;
}

$template = self::str_replace_once($plugin,$attr_arr_all['content'],$template);
$template_parse = self::str_replace_once($plugin,'{'.$name.'}',$template_parse);
$template_parse = str_replace(array('{|-','-|}'),'',$template_parse);//清空边界
if($is_new)
{
$add_fields[$name] = array(
'name'=>$name,
'leipiplugins'=>$attr_arr_all['leipiplugins']
);
}

$template_data[$pno] = $attr_arr_all;

}

}
}
$parse_form = array(
'fields'=>$fields,
'template'=>$template,
'parse'=>$template_parse,
'data'=>$template_data,
'add_fields'=>$add_fields,
);
//print_r($parse_form);exit;
return $parse_form;


}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template