[PHP] Line Breaks in dynamic Download
I have a script that allows clients to download their email lists from a database. However I can not get the 'new line' characters (\n \r) to do their job in Notepad when the download is prompted and the file saved to disk. I've simplified the problem with the code below. Both \n and \r display as 'null' or undefined characters in Notepad. What am I doing wrong? ? $file = LINE ONE\nLINE TWO\rLINE THREE\n\r; header(Cache-control: private); header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo $file; ? http://www.helpelf.com/texttest.php Click here to run this code. You should be prompted to save the file. Open the resulting file in Notepad on your PC. Tell me if the newlines show as 'null' characters or if each LINE ONE, LINE TWO, etc. shows up on their own lines. Mac users also welcome to try in Simpletext/BBedit. Much thanks, Kevin Stone [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Line Breaks in dynamic Download
? $file = LINE ONE\nLINE TWO\rLINE THREE\n\r; Try this instead and see if it works... $windowsNewLine = chr(13) . chr(10); $file = LINE ONE{$windowsNewLine}LINE TWO{$windowsNewLine}LINE THREE{$windowsNewLine}; Not sure if Notepad will interpret \r\n correctly... Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Line Breaks in dynamic Download
[snip] I have a script that allows clients to download their email lists from a database. However I can not get the 'new line' characters (\n \r) to do their job in Notepad when the download is prompted and the file saved to disk. I've simplified the problem with the code below. Both \n and \r display as 'null' or undefined characters in Notepad. What am I doing wrong? ? $file = LINE ONE\nLINE TWO\rLINE THREE\n\r; header(Cache-control: private); header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo $file; ? [/snip] They're undefined characters. Notepad has this whole silly Windoze thing going on requiring a carriage return-linefeed at the end of each line you wish break. So you will either need to do \r\n or chr(13) chr(10) at each place you want a break (or a ^m). This happens to be an anomaly with Notepad, which unlike popular belief is not really a text editor, it just plays one on TV. Open your file in WordPAd, and prepare to be amazed. HTH! Jay * * Texas PHP Developers Conf Spring 2003* * T Bar M Resort Conference Center* * New Braunfels, Texas * * Contact [EMAIL PROTECTED] * * * * Want to present a paper or workshop? Contact now! * * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Line Breaks in dynamic Download
Much thanks. This works but now it won't propmpt the download. Once the headers are sent anything going to std out is part of the download correct? But this is just printing to the screen. Any thoughts there? ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(13).LINE TWO.chr(10).LINE THREE; ? -Kevin - Original Message - From: Jay Blanchard [EMAIL PROTECTED] To: 'Kevin Stone' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, September 06, 2002 12:55 PM Subject: RE: [PHP] Line Breaks in dynamic Download [snip] I have a script that allows clients to download their email lists from a database. However I can not get the 'new line' characters (\n \r) to do their job in Notepad when the download is prompted and the file saved to disk. I've simplified the problem with the code below. Both \n and \r display as 'null' or undefined characters in Notepad. What am I doing wrong? ? $file = LINE ONE\nLINE TWO\rLINE THREE\n\r; header(Cache-control: private); header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo $file; ? [/snip] They're undefined characters. Notepad has this whole silly Windoze thing going on requiring a carriage return-linefeed at the end of each line you wish break. So you will either need to do \r\n or chr(13) chr(10) at each place you want a break (or a ^m). This happens to be an anomaly with Notepad, which unlike popular belief is not really a text editor, it just plays one on TV. Open your file in WordPAd, and prepare to be amazed. HTH! Jay * * Texas PHP Developers Conf Spring 2003* * T Bar M Resort Conference Center* * New Braunfels, Texas * * Contact [EMAIL PROTECTED] * * * * Want to present a paper or workshop? Contact now! * * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Line Breaks in dynamic Download
Here's what your file contains: ccadev:/# od -c TEST.txt 000L I N E O N E \r L I N E T W 020O \n L I N E T H R E E 034 Wordpad handles it. Notepad does not. But you have different line terminators for each line Later, Larry Irwin - Original Message - From: Kevin Stone [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, September 06, 2002 2:48 PM Subject: [PHP] Line Breaks in dynamic Download I have a script that allows clients to download their email lists from a database. However I can not get the 'new line' characters (\n \r) to do their job in Notepad when the download is prompted and the file saved to disk. I've simplified the problem with the code below. Both \n and \r display as 'null' or undefined characters in Notepad. What am I doing wrong? ? $file = LINE ONE\nLINE TWO\rLINE THREE\n\r; header(Cache-control: private); header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo $file; ? http://www.helpelf.com/texttest.php Click here to run this code. You should be prompted to save the file. Open the resulting file in Notepad on your PC. Tell me if the newlines show as 'null' characters or if each LINE ONE, LINE TWO, etc. shows up on their own lines. Mac users also welcome to try in Simpletext/BBedit. Much thanks, Kevin Stone [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Line Breaks in dynamic Download
[snip] ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(13).LINE TWO.chr(10).LINE THREE; ? [/snip] Try this; ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(13).chr(10).LINE TWOchr(13).chr(10).LINE THREE; ? HTH! Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Line Breaks in dynamic Download
I used different chars for testing purposes only. chr() function helped with the original problem. Again, the new problem is that the Text is not downloading as a file. It is just being printed to the screen. Any ideas why it wouldn't be prompting the downloading? -Kevin - Original Message - From: Jay Blanchard [EMAIL PROTECTED] To: 'Kevin Stone' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, September 06, 2002 1:21 PM Subject: RE: [PHP] Line Breaks in dynamic Download [snip] ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(13).LINE TWO.chr(10).LINE THREE; ? [/snip] Try this; ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(13).chr(10).LINE TWOchr(13).chr(10).LINE THREE; ? HTH! Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Line Breaks in dynamic Download
snip Again, the new problem is that the Text is not downloading as a file. It is just being printed to the screen. /snip I tested the following code: ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(10).LINE TWO.chr(10).LINE THREE; ? on a WinNT 4.0 with Apache 1.3.24 and PHP 4.2.3 and did not come across the same issues as you. I was prompted to download or open the file. However, when I did open the file with Notepad it did not contain any line breaks, Wordpad did have the line breaks. HTH Steven -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Line Breaks in dynamic Download
Thank you all very much. Turns out it was yet another browser cache issue and a quick reboot solved the problem. Minor modification of just two lines and I'm back in business. It's the details that'll kill you, eh? :) Final code... ? header(Cache-control: private); header(Content-Type: application/octet-stream); header(Content-Disposition: attachment; filename=emaillist.txt); $query = SELECT $field_str FROM helpelf_email_lists WHERE clientid='$view' ORDER BY timestamp DESC; $result = mysql_query($query, $db); while ($row = mysql_fetch_row($result)) { $file_array = array(); for ($i=0; $icount($row); $i++) { // Replace any commas with periods. $row[$i] = str_replace(',', '.', $row[$i]); $tmp_row = addslashes($row[$i]); $file_array[] = $enclosed.$tmp_row.$enclosed; } $file_tmp = implode($separator, $file_array); echo $file_tmp.chr(13).chr(10); } ? Again much thanks to everyone who helped me. -- Kevin Stone [EMAIL PROTECTED] - Original Message - From: Steven [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, September 06, 2002 1:50 PM Subject: [PHP] Line Breaks in dynamic Download snip Again, the new problem is that the Text is not downloading as a file. It is just being printed to the screen. /snip I tested the following code: ? header(Content-type: application/octet-stream); header(Content-Disposition: attachment; filename=TEST.txt); echo LINE ONE.chr(10).LINE TWO.chr(10).LINE THREE; ? on a WinNT 4.0 with Apache 1.3.24 and PHP 4.2.3 and did not come across the same issues as you. I was prompted to download or open the file. However, when I did open the file with Notepad it did not contain any line breaks, Wordpad did have the line breaks. HTH Steven -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php