Append text to lines in text document, using PHP?

Use file to get each line of the file. Then iterate each line, append your text and save the file using file_put_contents.

If it's in the file, use file() to read the file, you'll get array of lines. If it's a string, use explode("\n", $string). If you don't know the separator, you can use preg_split("/(\n|\r|\n\r)/", $string).

Then loop over the elements of the array and prepend the string, then use join("\n", $arr) to convert array back to string. If you need to preserve separators, use preg_split as above with PREG_SPLIT_DELIM_CAPTURE option and skip delimiters when prepending strings. If you used file() the line ends are already there, so use file_put_contents("newfile", join('', $arr)) to write it back.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions