I have a php script that is reading a file in (file_get_contents). I want to replace all newlines with br’s, and strip out all other characters. However, I am getting an error when interpreting the contents into a javascript variable.
I think the guilty party is the “^Z” character, but I don’t know how to get rid of it. The “^M” is a git character, and I believe the “^Z” is actually part of the string itself.
How would I strip this character out in php?

Okay, my question was wrong before, so I have updated it with new content.
How do I ensure that all newlines are removed from a php string? This string is read in with file_get_contents, then javascript is dynamically created with the contents of the file. The “\n” is replaced with “NEW,” and the “\r” is replaced with “”.
However, I am getting an “Unexpected EOF” error, and when I copy the string and paste it into the console, something is giving me newlines. How do I make sure that ALL newlines (whitespace for that matter) is trimmed out?
trim()
str_replace
preg_replace
Have all been used, any help is greatly appreciated!

CTRL-Z is the DOS/Windows end-of-file character for text files. If you examine your input file, you’ll probably find that character in there.
It stems from the earliest days (CP/M no less) when files were an exact multiple of the disk sector size so you couldn’t have files that weren’t a multiple of that.
So, if you wanted to end the file earlier, you placed a special end-of-file character in there that the file reading routines would understand. This wasn’t really a problem for binary files since it didn’t matter if they had extraneous information at the end – it would most likely be ignored. However, you _didn’t want any rubbish at the end of your nice little WordStar 3.3 document.
The
^Zcharacter is code number 26 so you should be able to usestr_replacewith the\x1acharacter, something like: