1 Data Files Mon Jan 17, 2011 10:02 pm
Unknown Data
Registered Member
Data Files Learn PHP - Part 5 |
In some cases can it be a good idea to save the data in a textfile. It isn't so hard as it sounds. We are normally using these stuff with forums, counters ie. Just read the following and you'll hopefully learn how to do it. Open, add and write in a textfile We starts with a example.
• By using the command fopen will our textfile data.txt and w+ save the content in the varaible $data. • Now when we need to open the file data.txt can we use the fwrite command. In the parentheses is the file writtin, with the text that should be written. • At the end will the file getting closed with fclose. Read data from a textfile This time do we got following code.
And like before will I explain it, how it works. • When we are going to read a file, are we using the mode r. We could also have used w+, but it isn't necassary when we just are going to read the file. • To read the file, are we writting fgets. And the number 50 counts how many signs we wan't to read. • With fclose will the file close. Some modes Here is a list with following modes in use with fopen(). • "r" The file will be opened in a reading statement. • "r+" The file will be opened in a reading and writting statement. • "w" The file will be opened in a writting statement and it'll delete all content (creates a new one if it's necassary). • "w+" The file will be opened in a reading and writting statement and it'll delete all content (creates a new one if it's necassary). • "a" The file will be opened in a writting statement and it'll delete all content (creates a new one if it's necassary). • "a+" The file will be opened in a reading and writting statement and it'll delete all content (creates a new one if it's necassary). • "x" Creates and open a writting statement file (supported by PHP 4.3.2 and later is it only working on local files). • "x+" Creates and open a reading and writting statement file (supported by PHP 4.3.2 and later is it only working on local files). In the next lesson will we take a look at a little counter, that can be used on your own website. |
Notice : This tutorial is copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators. |