例如我现在有个html页面,其中有个 <textarea></textarea> 用来给用户输入东西。用户会按照下面的格式输入:例如:23=12,34
78=1,3
45=12,46,78,8
9=33然后用户提交, 提交后会将这些保存在一个叫 config.php的文件里,并且将上面的内容保存为数组:$shuzu = array(
"23"=>array
(
12,
34
),
"78"=>array
(
1,
3
),
"45"=>array
(
12,
46,
78,
8
),
"9"=>array
(
33
))
78=1,3
45=12,46,78,8
9=33然后用户提交, 提交后会将这些保存在一个叫 config.php的文件里,并且将上面的内容保存为数组:$shuzu = array(
"23"=>array
(
12,
34
),
"78"=>array
(
1,
3
),
"45"=>array
(
12,
46,
78,
8
),
"9"=>array
(
33
))
//demo1.php
<form action="demo2.php" method="POST">
<textarea name="array_info" ></textarea><input type="submit" value="submit">
</form>//demo2.php
$array_info = $_POST['array_info'];
$array = preg_split("/\s+/",$array_info);
$str_out = '$shuzu = array('."\n";foreach ($array as $key=>$val)
{
$val_piece = explode("=",$val); $keyinfo = $val_piece[0];
$valinfo = $val_piece[1];
$str_out .= '"'.$keyinfo.'"=>array('.$valinfo.'),'."\n";
}
$str_out = substr($str_out,0,-2);
$str_out .= "\n)";echo "this string will write into config.php :<hr/> ".$str_out;$fp = fopen("config.php","w+");fwrite($fp,$str_out);
fclose($fp);
echo "write file completed!";