To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > General Help

General Help Forum for General Help questions pertaining to PHP

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-03-2009, 11:02 PM   #1
totus
Junior Member
 
Join Date: Oct 2009
Posts: 17
tmpfile and newlines

Can someone explain how to get \n newlines into a tmpfile()?

Correction, I seem to be able to get them in there via fwrite but echoing them back shows all lines as one line after rewind.

hmm

Maybe I'd be better off sticking with creating a file and unlinking. Opinions??
totus is offline   Reply With Quote
Old 11-03-2009, 11:39 PM   #2
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,128
\n should work.

Are you echoing them back in a browser? I.e., a browser that's trying to render it as HTML? I'm presuming you're not talking about Windows Notepad (which doesn't recognise linebreak characters as linebreaks) of course.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-04-2009, 05:50 PM   #3
totus
Junior Member
 
Join Date: Oct 2009
Posts: 17
Thanks for the insight Weedpacket. I discovered the difference between \n and \r\n yesterday. My woes exist below, I don't think its a line break problem but more of a coding problem. The echo statement works fine, however, I'm not able to populate $mbody - email shows up with $mbody empty.

Code:
$programsn = tmpfile();

if (isset($HRA)) {
   fwrite($programsn, "Health Risk Assessment\n"); }

// email confirmation
$to = "me@me.com";
$subject = "Hi!";
$hbody = file_get_contents('./includes/email-head.txt', true);
$fbody = file_get_contents('./includes/email-foot.txt', true);
fseek($programsn, 0);
echo fread($programsn, 1024);

$mbody = fread($programsn, 1024);
$body = $hbody . $mbody . $fbody;
mail($to, $subject, $body);

close($programsn);

Last edited by totus; 11-04-2009 at 05:52 PM. Reason: removing email address
totus is offline   Reply With Quote
Old 11-04-2009, 06:25 PM   #4
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,128
PHP Code:
echo fread($programsn, 1024);

$mbody = fread($programsn, 1024);
You fread() 1024 bytes of $programsn, and then you fread() another 1024 bytes of $programsn
PHP Code:
$mbody = fread($progamsn, 1024);
echo
$mbody;
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-05-2009, 06:19 PM   #5
totus
Junior Member
 
Join Date: Oct 2009
Posts: 17
Thank you Weedpacket for your eagle eyes
totus is offline   Reply With Quote
Reply

Bookmarks

Tags
newlines, tmpfile


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 04:39 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.