<?php
$fp = fopen('/file.txt', 'a+');
fseek($fp, 2, SEEK_SET);
fwrite($fp, $newLine."\n");
fclose($fp);
?>
$file = 'extensions.txt';
$txt = file_get_contents($file); //converts a file to a string
$Blocks = explode(PHP_EOL, $txt); //puts file in an array
$pLine="[users]";
$location=array_search($pLine,$Blocks)+1;
echo $location;
$data="exten=>this is a new line";
array_splice( $Blocks,$location , 0, $data );
$txt = implode("\n", $Blocks);
file_put_contents($file, $txt);