Ok, this is driving me nuts. All I want to do is open a file, search for a string, insert a string immediately after the search string and close the file. I am using fopen()fread() preg_match and preg_replace to open the original file, read it all into a string and then replace the search string with the search string plus the new string, then fopen() fwrite() and fclose() to create a new file by outputting the new string.
The problem is that when I use fopen in 'b' mode everything is fine except for the string that gets added during preg_replace doesn't format correctly. (I get the weird squares instead of newlines on windows machines.) If I use 't' mode for windows, everything is screwed up EXCEPT for the new string. WTF??? Man I miss Perl. Everything outputs to the screen correctly, but the file has this "text" and "binary" issue which I can't seem to get around. I want the script to be cross-platform, but this problem in windows is driving me up the wall. Anyone got any advice?
The problem is that when I use fopen in 'b' mode everything is fine except for the string that gets added during preg_replace doesn't format correctly. (I get the weird squares instead of newlines on windows machines.) If I use 't' mode for windows, everything is screwed up EXCEPT for the new string. WTF??? Man I miss Perl. Everything outputs to the screen correctly, but the file has this "text" and "binary" issue which I can't seem to get around. I want the script to be cross-platform, but this problem in windows is driving me up the wall. Anyone got any advice?