nejolley Posted September 21, 2009 Share Posted September 21, 2009 I've got an issue that I believe has something to do with the encoding of my text file. But I'm not sure how I go about changing that. In short, what I'm really trying to accomplish is that when the file I've just created with PHP is opened in Notepad that it is formated exactly the way I intended it to. Particulary how the file handles carriage returns. So when I send a carriage return to the file I want to see a new line and not as a symbol "[]". Link to comment https://forums.phpfreaks.com/topic/175023-carriage-returns/ Share on other sites More sharing options...
p2grace Posted September 21, 2009 Share Posted September 21, 2009 I'd need to see your input code to determine why you see a '[]' for line breaks. Line breaks are specified by using \r\n. Link to comment https://forums.phpfreaks.com/topic/175023-carriage-returns/#findComment-922455 Share on other sites More sharing options...
nejolley Posted September 21, 2009 Author Share Posted September 21, 2009 It's not exactly a "[]" but just a small closed little box where I've inserted a \n. But here is the code: $stringData = "%BTW% /AF=c:\labels\lp_4x2_bin_id.btw /D=<Trigger File Name> /PRN=\"\\\dclaptop\Zebra S4M (203 dpi) - ZPL\" /R=3 /P /DD \n%END%\n"; fwrite($fh, $stringData); Link to comment https://forums.phpfreaks.com/topic/175023-carriage-returns/#findComment-922472 Share on other sites More sharing options...
nejolley Posted September 21, 2009 Author Share Posted September 21, 2009 Alright, I figured it out and found the solution. Here's my updated code for those who are curious: $fh = fopen($myFile, 'wb') or die("can't open file"); $stringData = "%BTW% /AF=c:\labels\lp_4x2_bin_id.btw /D=<Trigger File Name> /PRN=\"\\\dclaptop\Zebra S4M (203 dpi) - ZPL\" /R=3 /P /DD \r\n%END%\r\n"; fwrite($fh, $stringData); According the the PHP.net "Windows based systems use \r\n as the line ending characters " Link to comment https://forums.phpfreaks.com/topic/175023-carriage-returns/#findComment-922484 Share on other sites More sharing options...
kenrbnsn Posted September 21, 2009 Share Posted September 21, 2009 The other option is to open the file with wordpad, which knows that \n is a line terminator. Ken Link to comment https://forums.phpfreaks.com/topic/175023-carriage-returns/#findComment-922487 Share on other sites More sharing options...
nejolley Posted September 21, 2009 Author Share Posted September 21, 2009 True. But in my case these files that are being created aren't being made for humans to open up and read. Instead, another program which I use to create barode labels reads in the text file. This other program didn't know how to handle the special character that was being created in my file and would error off. Now with the file formatted correctly I'm now printing labels successfully. Link to comment https://forums.phpfreaks.com/topic/175023-carriage-returns/#findComment-922494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.