<?php $file = 'file.txt'; $add = 'some text'; $x = file_get_contents($file); $x = str_replace("\r\n",$add."\r\n",$x); echo $x;