|
 |
|
 |
06-14-2006, 10:29 AM
|
#1 (permalink)
|
|
Code Monkey
Join Date: Jun 2006
Posts: 65
|
Creating TXT Files
I can write to and read from a text file using fopen, fread, fwrite and fclose, but can I create text files?
|
|
|
06-14-2006, 11:06 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
|
Sure you can
PHP Code:
$file = fopen("my_file.txt", "w"); fwrite($file, "Some test string"); fclose($file);
Just read up on the modes for fopen()
|
|
|
06-14-2006, 12:52 PM
|
#3 (permalink)
|
|
Code Monkey
Join Date: Jun 2006
Posts: 65
|
thanks!
|
|
|
09-14-2006, 06:16 AM
|
#4 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
OK - that works . . . I used this example (with a little modification) to my PHP shells for logging what files I'm actually displaying . .
$recipe = 'recipes/'.$_GET['recipe'].'.html';
if (is_file($recipe)) {
$file = fopen("logfile.txt", "a");
fwrite($file, date("M d Y H i s").' RINDEX '.$_GET['recipe']."/n");
fclose($file);
include($recipe);
}
For some reason, the /n isn't creating a new line in the file. If I take away
the quotes, I get a 'divide by zero' error. If I replace the double quotes with single quotes, it behaves the same way.
Any insights?
Thanks in advance
Frank
|
|
|
09-14-2006, 06:28 AM
|
#5 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
Hey it's Chef Frank!
use backslash n instead of a forward slash.
PHP Code:
fwrite($file, date("M d Y H i s").' RINDEX '.$_GET['recipe']."\n");
__________________
Mike
|
|
|
09-14-2006, 06:40 AM
|
#6 (permalink)
|
|
Code Monkey
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
|
Well, Duh!!!
I looked at that sucker about 100000000 times and never saw that!!
That's what I get for slinging hash instead of code for a living now!!
Thanks for providing the second set of eyes! I check in from time to time, but I have been more concerned with content than structure on the site. I get some neat statistics from my server, but unfortunately, because of how I wrote the site, I know how many people look at recipes, but I didn't know which recipes they looked at. This should correct that problem.
I may be over on the CSS forum soon - I'm going to rewrite everything with CSS instead of using tables. THAT will be a fun project.
Regards!
Frank
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 05:28 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|