21,886
社区成员
发帖
与我相关
我的任务
分享
/**
* wn_form_data_transact()回调的函数
* @param array 分割出来的字符串数组
*/
function str_callback($mth){
foreach( $mth as $k => $val ){
//提取value值
if( strpos($val,'value') && ( $k != 0 ) ){
$val = strtolower(trim($val)); //把字母转成小写后进行配对
/*
* 把input值分割出来
*/
if(strpos( $val, 'value="' )){
$s = split( 'value="', $val );
$s = split( '"', $s[1] );
}elseif( strpos( $val, "value='" ) ){
$s = split( "value='", $val );
$s = split( "'", $s[1] );
}else{
$s = split( 'value=', $val );
$s[0] = $s[1];
}
}
/*
* 把select值提取出来
*/
if( strpos( strtolower($val), 'option') ){
$val = strtolower($val);
$strc = split( '<option', $val );
foreach( $strc as $sk => $sv ){
if( strpos( $sv, 'selected' ) ){
$strd = split( '>', $sv );
}
}
$s[0] = $strd[1];
}
$values = $s[0];
$values = trim($values, "'");
$values = trim($values, '"');
//提取ID值
if( trim($val) == 'id' ){
$id = $mth[$k+1];
}
}
return "<span id='".$id."'>".$values."</span>";
}
/**
* 表单分析
* @param string 字符串
*/
function wn_form_data_transact( $string ){
if( !$string ) return false;
/*
* 正则表达式
*/
$strPreg['input'] = '/<[\/\!]*?input([^<>]*?)(id)[\s]*?\=[\s]*?[\"|\']?([\d|\b|\B|\D]+?)?[\"|\']([^<>]*?)>/si';
$strPreg['select'] = '/<[\/\!]*?select[^<>]*?(id)[\s]*?\=[\s]*?[\"|\']?([\d|\b|\B|\D]+?)?[\"|\'][^<>]*?>.*?<\/select>/si';
/*
* 得到可用数据后回调一个函数替换
*/
foreach( $strPreg as $key => $val ){
$string = preg_replace_callback($val,"str_callback",$string);
}
return $string;
}