Well, I was wondering if anyone could give me a script I can use to get a entered value from a post form (e.g Username) and check to see if the username exists in a plain txt file I have with usernames separated by a line break, thanks in advanced.

Recommended Answers

All 5 Replies

Try something along the lines of the following:

<?
$file='file.txt'; //set the file name and path
$lines=explode('
',file_get_contents($file));
foreach ($lines AS $line) {
    if ($_POST['username']==$line) {
        $userfound='true'; break;
        }
    }

if ($userfound=='true') {
    //script for if user is found in text file
    }
?>

Although the above code should work you may find that the function preg_match will be more recourse efficient.
Have a nice day.

A sample preg_match script:

$userfound = (preg_match("/\b$username\b/") === 1);

Hello,

Basically I have to do the following task but I require a lot of help. Is it posible for somebody to help me with doing the following php coding and designing the interface, please. I basically have to code this into dreamweaver and play the game. Is it possible for somebody to urgently to help me out here. I urgently need this help, please.

The task is below:

Create a game of “Play Your Cards Right” (otherwise known as “higher/lower”) using PHP to play against the computer.
For those unsure as to the rules of this game: a card is dealt from the pack and the player must guess whether the next card is higher or lower. For example: if the first card dealt is the 3 of diamonds, it is likely that the player will opt for higher as the laws of probability
dictate that in all likelihood the value of the next card will be higher
than a 3.
On opting for higher or lower a new card is dealt. If the player’s guess was correct then the process is repeated. If they guess wrong then the game is over.
Usually the player will win the game on guessing correctly a set
number of cards (somewhere between 5 and 10 is fine).

Please send the coded files to the following email address Uhussain@rediffmail.com, please as have to upload them onto an ftp program to upload to the website. Please help urgently

Thank you

Your post is one of the worst i've ever seen (i'm sure others would have some stories to tell). First, you hijacked a completely unrelated thread. Secondly, you essentially demand someone write a program for you (most likely homework) with the usual fake appreciation and "urgency". Finally, you ask us to email you the code. That just doesn't happen!

Hello,
Please send the coded files to the following email address Uhussain@rediffmail.com, please as have to upload them onto an ftp program to upload to the website. Please help urgently

Thank you

lol. If you want somebody to do the job for you then the are people you can pay for that sort of thing. But if you do wish to receive any help on the forums then you will need to make an attempt to do it yourself first then when errors appear, you then present relevent sections of your code on the forums for advice on how to resolve the coding errors. However, if you ask people to make such a large scale project from scratch that is what I would call getting somebody to do your homework.

So if you think you can't even start by yourself, try doing different project that is a lot easier to get the hang of php then over time with experimentation you will learn more of the functions untill you know enough to make this game. An example of myself trying to go to large scale projects without the basics is my first daniweb post. I asked in the c++ section how to make a program to animate 3D humans and convert the moving people to animations. Never happened because you need to learn the basics first.
So try some tutorials and fiddle around with php untill things for this project seem easier to achieve and that you are able to write the code with possible errors that we may be able to fix.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.