Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This bit of code is supposed to write a little message to a file called data.dat and then print a confirmation message saying everything went ok. Now everything works exept that when you open the file that was written to, "data.dat", there isn't a message just giberish. Anybody know why?

Let me try that again:
This bit of code is supposed to write a little message to a file called data.dat and then print a confirmation message saying everything went ok. Now everything works exept that when you open the file that was written to, "data.dat", there isn't a message just giberish. Anybody know why?
/\?php
$file_name = "data.dat";
// absolute path : \home\data.dat$file_pointer = fopen($file_name, "w");
// "w" is the mode, or the action we're
// going to perform on the file
// Detailed info at end of pagefwrite($file_pointer, "what you wanna write");
// Writing to the file, after truncating it
// to 0 bytesfclose($file_pointer);
// everything comes to an end!print "data written to file successfuly";
?/\

This should work...
$fp = "data.dat"; // FILE POINTER
fopen($fp, "w"); // OPEN FILE, TRUNCATE TO 0
fputs($fp, "Some text here"); // PUT DATA INTO FILE
fclose($fp); // CLOSE FILEecho "Data written successfully to file!";
?>
(If that didn't post right, I'll try again)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |