复制文件并在规定行插入数据

/*public function copyfile($str,$pre){
copy('test.php','array.php');
$arrInsert = insertfile("array.php", $str, 3, 0);
unlink("array.php");
foreach($arrInsert as $value)
{
file_put_contents($pre.".php", $value, FILE_APPEND);
}

}
public function insertfile($source, $s, $iLine, $index) {
$file_handle = fopen($source, "r");
$i = 0;
$arr = array();
while (!feof($file_handle)) {
$line = fgets($file_handle);
++$i;
if ($i == $iLine) {
if($index == strlen($line)-1)
$arr[] = substr($line, 0, strlen($line)-1) . $s . "n";
else
$arr[] = substr($line, 0, $index) . $s . substr($line, $index);
}else {
$arr[] = $line;
}
}
fclose($file_handle);
return $arr;
}*/
posted @ 2015-09-09 10:33  梁小粽  阅读(206)  评论(0编辑  收藏  举报