Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-14-2006, 10:29 AM   #1 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
Question 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?
markster is offline   Reply With Quote
Old 06-14-2006, 11:06 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
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()
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 06-14-2006, 12:52 PM   #3 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
thanks!
markster is offline   Reply With Quote
Old 09-14-2006, 06:16 AM   #4 (permalink)
ChefFrank
Code Monkey
 
ChefFrank's Avatar
 
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
ChefFrank is on a distinguished road
Send a message via Yahoo to ChefFrank
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
ChefFrank is offline   Reply With Quote
Old 09-14-2006, 06:28 AM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
Hey it's Chef Frank!

use backslash n instead of a forward slash.

PHP Code:
fwrite($filedate("M d Y H i s").' RINDEX '.$_GET['recipe']."\n"); 
__________________
Mike
sde is offline   Reply With Quote
Old 09-14-2006, 06:40 AM   #6 (permalink)
ChefFrank
Code Monkey
 
ChefFrank's Avatar
 
Join Date: Mar 2006
Location: Woodbury, CT
Posts: 38
ChefFrank is on a distinguished road
Send a message via Yahoo to ChefFrank
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
ChefFrank is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating .swf files at random with JavaScript? VisionsIC HTML, XML, Javascript, AJAX 0 05-18-2005 11:12 AM
Temp Internet Files - Delete wendyng HTML, XML, Javascript, AJAX 0 04-18-2005 10:30 PM
.h files needed Maani Standard C, C++ 7 02-02-2005 04:59 AM
Installing and using CMUgraphics library. Valmont Standard C, C++ 12 03-29-2003 08:39 AM
All Class Files mixingsoup PHP 12 12-04-2002 06:49 AM


All times are GMT -8. The time now is 05:28 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting