|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
New line caariage return
I want to generate some files at my job on a NT machine. When I press the button "SAVE" I want the file to be saved on a UNIX machine by sending it by FTP.
This is working well but when I'm opening the file on the UNIX machine I see a square on the place where you should have a carriage return. When I'm opening the file on the NT machine I don't see squares (control characters). I tried to send the file in FTP_Binary and in FTP_ASCII but I have the problem in the two cases. The text I am sending is like: $textfield="Hello this is a test\n This is a test2\n And a lot more"; $fp = fopen($temp, "w+"); $write=fwrite($fp, $textfield); I tried to upload the generated files with an ordinarry FTP program (like WSFTP) and there I didn't encounter this problem //AND i saved my file as unix format with textpad and uploaded it with my FTP script. (FTP program does auto convert the file to unix format) So i want to do the DOS format to UNIX format conversion it with a script. I read in a nwsgrp that WIN machine = \r\n and on Unix machine = \n. (new line) But I am saving it with "\n", so this is the format for an UNIX machine. When I open my file with a hex editor on windows i see OD OA = \r\n. So it seems that Windows automatically adds the \r. I tried then to use $textfield=str_replace("\r\n","\n",$textfield); But still the same problem. CAN PLEASE SOMEONE HELP ME. Thanks in advance, Frederick |
|
#2
|
|||
|
|||
|
Try:
$textfield = preg_replace("/(\015\012)|(\015)|(\012)/","",$textfield); or maybe: $textfield = preg_replace("/(\015\012)|(\015)|(\012)/","\n",$textfield); |
|
#3
|
|||
|
|||
|
The solution
I found the solution. I have to open my file binary to write:
fopen ($test,wb+) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > New line caariage return |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|