Jump to content

Shere my file lerning script.


redarrow

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.

[code]
<?php


// post all varables

$user_id=$_POST['user_id'];

$filename=$_POST['filename'];

$filemode=$_POST['filemode'];

$message=$_POST['message'];

$username=$_POST['username'];


//set all varables

$username="redarrow.txt";

$user_id="0002";

$filename="test.txt";

$filemode="a";

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


// see if directory exist using is_dir.

if(!is_dir($user_id)){

// make a dir using mkdir.

$a=mkdir($user_id);
}

// if the file is there using file_exists.

if(file_exists($user_id)){

// open the dir using fopen.

$b=fopen("$user_id/$filename","$filemode");

// write to that file using fwrite.

$c=fwrite($b,$message);

// close the fopen to do a rename.
fclose($b);

//rename the file using rename.

$d=rename("$user_id/$filename","$user_id/$username");
}

// open the dir with fopen

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

// loop trow the fopen dir filename.

while(!feof($e)){

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

$dis=fgets($e);

//echo the information to the screen.

echo $dis;

}

//close e fopen
fclose($e);

?>
[/code]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.