<?php
function replace_lines($files, $lines, $text){
if (file_exists($files)){
if ($lines!==""){
if ($text!=""){
$file = file($files);
$fp = fopen($files, "a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
foreach($file as $key=>$val){
if ($lines==$key) {
fputs($fp,"$text\r\n");
} else {
fputs($fp,$val);
}
}
fflush($fp);
flock ($fp,LOCK_UN);
fclose($fp);
}}}
}