943,589 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4361
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 30th, 2008
0

Re: help with printing multiple lines print a txt file

I guess that because your printing a receipt and you don't need an images, TEXT would probably be the best option (If it works just as well). Faster printing would indicate it's doing less work which can't be a bad thing.

You could use the function file_get_contents($filename) to get the contents of the file as a string. Try something like the following code:

php Syntax (Toggle Plain Text)
  1. $text_to_print = file_get_contents('receipt.txt');
  2. //Use this next line only if it doesn't work without it,
  3. //ie prints "Text \n\nTo print" instead of "Text \nTo print"
  4. $text_to_print = str_replace('\n', '\r\n', $text_to_print);
  5.  
  6. //yada yada, printer stuff
  7. printer_write($handle, $text_to_print);
  8. //yada yada, more printer stuff

That should all work I reckon, I reckon.

BTW, when do you write the contents to the file receipt.txt ? If it's earlier on in the script and you don't need to keep receipt.txt then you may as well skip that process. For example:

php Syntax (Toggle Plain Text)
  1. $text_to_print = '';
  2. //load mysql info into an array using:
  3. $data = mysql_fetch_array($result, MYSQL_ASSOC);
  4.  
  5. $text_to_print .= "Name: $data['name']\r\n";
  6. $text_to_print .= "Date: $data['date']\r\n";
  7. //etc.

php.net is the best place to get help on any specific function in my humble opinion.
Last edited by humbug; Oct 30th, 2008 at 11:08 pm. Reason: One letter makes all the difference
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Nov 2nd, 2008
0

Re: help with printing multiple lines print a txt file

hi all

having spent a large amount of time studing the ways to print using php I have finaly figured out the best solution. I have decided NOT to use the text file, but to print directly from a query to the mysql database. the function printer_draw_text is the way forward which can be used multiple times in one page.
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC