Jump to content

Type of .txt report


matfish

Recommended Posts

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
Link to comment
Share on other sites

[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 here
echo "Email Address: ".$email_record['email']; //break here
echo "Date: ".date("d-m-Y H:i:s",strtotime($email_record['log_timestamp'])); //break x 2 here

echo "Subject: ".$email_record['subject']; //break here
echo "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
Link to comment
Share on other sites

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?

Regards
Huggie
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

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 :(
Link to comment
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.