if( $_POST )
{
$str = '23=12,34 78=1,3 45=12,46,78,89=33';
$content=nl2br($str);
$content=str_replace(" ","",$content);
$arr=explode("
",$content);
$result=array();
foreach ($arr as $value)
{
$k=explode("=",$value);
$result[]=array($k[0]=>$k[1]);
}
//数组转换成字串
function arrayeval($array, $level = 0) {
$space = '';
for($i = 0; $i
$space .= " ";
}
$evaluate = "Array $space( ";
$comma = $space;
foreach($array as $key => $val) {
$key = is_string($key) ? '''.addcslashes($key, ''\').''' : $key;
$val = !is_array($val) && (!preg_match("/^-?d+$/", $val) || strlen($val) > 12 || substr($val, 0, 1)=='0') ? '''.addcslashes($val, ''\').''' : $val;
if(is_array($val)) {
$evaluate .= "$comma$key => ".arrayeval($val, $level + 1);
} else {
$evaluate .= "$comma$key => $val";
}
$comma = ", $space";
}
$evaluate .= " $space)";
return $evaluate;
}
//把结果写到文件
$config=arrayeval($result);
$strwrite="";
$fp=fopen('config.php','w');
fwrite($fp,$strwrite);
fclose($fp);
}
?>