matfish Posted December 18, 2006 Share Posted December 18, 2006 Hi, Iv got a database which is a log of emails (subject, email addy, body) and I want to create a text file of a log of them all. Iv got it looping though and it records it to a text file for on the fly download, but the nl2br isnt working so Iv got subject, email and body all squished up all together.Iv tried adding "[space & line break here to try and cheat]" and string replace but to a text file its just not happening.Any ideas? nl2br works when displaying the logs via html/php but when exporting to a text file its not putting them in...Many ta's Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/ Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 You don't want to use nl2br() at all. You want to leave them as new lines...If you provide your code we'll be able to help more.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/#findComment-143678 Share on other sites More sharing options...
matfish Posted December 19, 2006 Author Share Posted December 19, 2006 [code]<?//my includes here$p = "email_log_".date("d_m_y").".txt";header('Cache-Control: must-revalidate, post-check=0, pre-check=0');header("Content-type: text/plain");header("Content-Disposition: attachment; filename=\"$p\"");header("Content-Transfer-Encoding: binary");$email_list = getRows("logID, email, log_timestamp, subject, body", "email_logs", "log_timestamp >= '2006-12-13'");foreach ($email_list as $email_record){ echo "Log ID: ".$email_record['logID']."-----------------------------"; //break hereecho "Email Address: ".$email_record['email']; //break hereecho "Date: ".date("d-m-Y H:i:s",strtotime($email_record['log_timestamp'])); //break x 2 hereecho "Subject: ".$email_record['subject']; //break hereecho "Message: ".strip_tags($email_record['body']); //break here}?>[/code]There above produced the following:[quote]Log ID: 833-----------------------------Email Address: craig@hardbyte.co.ukDate: 13-12-2006 00:00:18Subject: Website - Feedback/CommentsMessage: Mr Martyn Lidbury has left the following feedback about the your website:Hello. this is where the message was.this was another paragragh. this was where is said "regards". this is where he put his nameLog ID: 834----------------------------- blah blah for the next record[/quote]nl2br and \n doesnt work so Iv left it as //break here - any ideas?Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/#findComment-144332 Share on other sites More sharing options...
matfish Posted December 19, 2006 Author Share Posted December 19, 2006 I added strip tags to the body because its recorded to the database including <br> and <p> tags - how come they work but not when adding them where I want to add them?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/#findComment-144335 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 You just need to print the newlines...[code]<?//my includes here$p = "email_log_".date("d_m_y").".txt";header('Cache-Control: must-revalidate, post-check=0, pre-check=0');header("Content-type: text/plain");header("Content-Disposition: attachment; filename=\"$p\"");header("Content-Transfer-Encoding: binary");$email_list = getRows("logID, email, log_timestamp, subject, body", "email_logs", "log_timestamp >= '2006-12-13'");foreach ($email_list as $email_record){ echo "Log ID: ".$email_record['logID']."-----------------------------\n";echo "Email Address: ".$email_record['email']."\n";echo "Date: ".date("d-m-Y H:i:s",strtotime($email_record['log_timestamp']))."\n\n";echo "Subject: ".$email_record['subject']."\n";echo "Message: ".strip_tags($email_record['body'])."\n";}?>[/code]Incidentally, is the Content-Transfer-Encoding correct? If it's just text, should it not be in ASCII?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/#findComment-144340 Share on other sites More sharing options...
matfish Posted December 19, 2006 Author Share Posted December 19, 2006 [quote]Types of Content-Transfer-Encoding include 7 bit unencoded 7 bit Ascii quoted printable 7 bit Ascii + special codes for 8 bit Ascii base64 encodes binary data in 3 byte chunks as 4 Ascii codes 8 bit unencoded 8 bit Ascii - unsafe binary unencoded binary - unsafe[/quote]Nope, still no joy. How come there is the br and p line breaks after strip tagging the body but it wont happen with the rest?ooo - quick idea, brb Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/#findComment-144476 Share on other sites More sharing options...
matfish Posted December 19, 2006 Author Share Posted December 19, 2006 I tryed grouping the lot into $message and then add my own br tags and then strip_tags the lot - but still nothing.Its actually printing the \n at the end of the lines..Then played around with some content-transfer-encoding and charsets, again - nothing :( Quote Link to comment https://forums.phpfreaks.com/topic/31116-type-of-txt-report/#findComment-144493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.