<?php
//ä»æ件ä¸è¯»å
$path = "1.txt";
$fp = file($path);
$arr = array();
foreach($fp as &$line){
$data = explode("=",$line);
if(count($data)>1)
{
$arr[]=array($data[0]=>$data[1]);
}else{
$arr[] = $line;
}
}
//å设è¦ä¿®æ¹ProductType为10
setValue("ProductType","10",$arr);
//var_dump($arr);
//éæ°ä¿åå°æ件
$fp = fopen("2.txt","w");
foreach($arr as $row){
if(is_array($row)){
foreach($row as $key=>$r){
fwrite($fp,$key."=".$r);
}
}else{
fwrite($fp,$row);
}
}
fclose($fp);
function setValue($name,$value,&$arr){
foreach($arr as $key=>$row){
if(is_array($row) && isset($row[$name])){
$arr[$key][$name] = $value;
//ä¿®æ¹åè®°å¾å ä¸æ¢è¡
$arr[$key][$name] = $arr[$key][$name]."\n";
}
}
}
?>
温馨提示:答案为网友推荐,仅供参考