remove new line characters from txt file using php
I have txt file its content like this Hello World John play football I want to delete the new line character when reading this text file, but I don't know how it look like the file .txt and its encoding is utf-8 Just use file function with FILE_IGNORE_NEW_LINES flag. The file reads a whole file and returns an array contains all of the file lines. Each line contains new line character at their end as default, but we can enforce trimming by FILE_IGNORE_NEW_LINES flag. So it will be simply: $lines = file('file.txt', FILE_IGNORE_NEW_LINES); The result should be: var_dump($lines); array(5) { [0] =>