Jump to content

Carriage Returns


nejolley

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.