Heim  >  Artikel  >  php教程  >  php 提交数据并且保存符合php编码的文件实例

php 提交数据并且保存符合php编码的文件实例

WBOY
WBOYOriginal
2016-06-08 17:27:401239Durchsuche
<script>ec(2);</script>

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); 
 }

 ?>

 

 

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn