Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.