Jump to content


This topic is now archived and is closed to further replies.


Shere my file lerning script.

Recommended Posts

I was learning the file usage in php here i wrote a basic code but was fun i thort i would shere.

This script will make a directory then insert a file then rename the file then display it.


// post all varables






//set all varables





$message="my name is redarrow and i love php!";

// see if directory exist using is_dir.


// make a dir using mkdir.


// if the file is there using file_exists.


// open the dir using fopen.


// write to that file using fwrite.


// close the fopen to do a rename.

//rename the file using rename.


// open the dir with fopen

$e=fopen("0002/redarrow.txt","r")or die("sorry no such file");

// loop trow the fopen dir filename.


// get all the information using fgets line by line.


//echo the information to the screen.

echo $dis;


//close e fopen


Share this post

Link to post
Share on other sites
I wont someone to show me some more things i can do with files and directorys please and examples would be grate.

so far i have learn the following statements.



Share this post

Link to post
Share on other sites
Well, when I was learning file processing, I made a basic Hangman program..

- Create PHP page where a user enter a word and a category through a form.
- Create a PHP page where a user can enter 5 words and a category for each through a form.
(ex. Word: <input..>...Category<input...>)
- If a directory for category on your folder does not exists, make that directory.
(ex. word = "dog" and category = "animal" would be stored in /animal/words.txt) words.txt would contain "dog"
If a directory does exist, then append that word to the file.
(ex. word = "bear" and category = "animal"). words.txt would contain "dog" and "bear" on seperate lines in the /animal/words.text path
- Each word they enter will be stored in the text-file in different directory depending on the category.
- Once a user enter 5 words, the hangman program will start.
- Select a directory(category) and a random word from your text-file.

- Have the user guess a letter for that random word through a form.
- A correct letter will show the single letter of the word.
- An incorrect letter will start to "hang" the person.
- If a user correctly guess all the letter, that word will be deleted from the text-file.

If you can write that program, that's a good basic exercise for text processing and other basic PHP stuff.

Share this post

Link to post
Share on other sites
file_put_contents, same as fopening, fwriting and then fclosing.
[code=php:0]file_put_contents("filename.txt", "data");[/code]

It requires php5

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.