How to create and format a text file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
photonatic
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 4:44 pm

How to create and format a text file?

Post by photonatic »

Hi all.

I want to create a string where text and variables are added in this string (see example below), and finally mail()'ed as an attachment. The text must be in plain, so no html. I would like to know how to format the text file so that I can have newlines and eventually tabulation when needed. However, it appears that \n and \t doesn't have any effect.

I have read that for html-pages, I need to use <br> instead, yet this is not a html-page but plain text.

I also understand that a newline is OS-dependent, ie in Win it should be \r\n, and in Linux it should be \n. I've tried both but the email is still messy.

Finally, in php.net I've seen an example how OR'ing some numbers can "create" a backspace. Is this the way to go to "create" newlines and tabulation? If so, what are the numbers to OR?

Thanks in advance!

$string = $data[0] . "\n";
$string .= $data[1] . "\n";
$string .= $data[2] . "\n";
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

i'm pretty sure i added tabs to my text file as i wrote it. it was in the installer and created the config file for you. but i forget how to do it off hand.

but i have to get home to show ya. unless someone else here knows how :)
photonatic
Forum Newbie
Posts: 8
Joined: Thu Jun 08, 2006 4:44 pm

Post by photonatic »

A friend pointed out the problem. I had defined the mail-header's Content-Type to text/html, so that the mail was interpreted as a html-page, thus the newline wouldnt work. Thanks MrPotatoes for ur reply anyway. :-)
Post Reply