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
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
There are different kind of newlines. This will remove all 3 kinds in
$string
:Just use
file
function withFILE_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:
The result should be:
If your going to be putting the lines into an array, an assuming a reasonable file size you could try something like this.
I note that the way it was pasted in the question, this text file appears to have space characters at the end of each line. I'll assume that was accidental.