Hi, I am working with a file which is basically an ascii file. Lets say the file is called file.txt and that it has 3 lines in it:
line1
line2
line3
I can successfully read the file with a:
#Open File for read
$fp = fopen("file.txt", "rb");
# Read in lines with fgets
while (!feof ($lines)) {
$buffer = $buffer."-".fgets($lines, 4096);
}
fclose($fp);
#Split up the string i made and get rid of the begingin "-"
$myarray = substr($buffer, 1);
$myarray = split("-", $myarray);
$acount = count($myarray);
# now to write it out to a clean file(Overwrite old)!
$fp = fopen("file.txt", "wb");
for ($i=0, $i<=$acount; $i++) {
fwrite($fp, $myarray[$i]."\n");
}
fclose($fp);
This is the general setup im using, I use the string length for the write command len+2 for the "\n". But Im getting results i dont like. If i open the file in Wordpad, I see the new lines correctly. But, if i open it with notepad, It give the line breaks and the entire set of lines is on one line. ive tried other options such as "\r" to try to get it to go down a line. But i just cant seem to figure this out. If anyne could help me get it in a new line in notepad I would appreciate it.
I can seem to use the file() function to do thsi, but im not able to edit the content...or at least not very easily. So if this can be done with fopen It would be much better for me.
TIA for any help