Read and Find on text file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Schwalbach
Forum Newbie
Posts: 2
Joined: Sun Dec 07, 2003 11:20 am

Read and Find on text file

Post by Schwalbach »

Hey, I have posted this a couple places now, finding no help what-so-ever, lol...but anyways, here it goes :)

I made a little mailing list and have a problem with it...People can sign up more than once! This is a flash integrated system, but I just need the php tp basically do this(The codes that I do try to include are probably wrong, so just stick with me)

Code: Select all

<?php

$outReceive = "output=".$outSend;
$update = "text.txt";
$email = $outSend;
$fp = fopen($update, "a");
$line = $outReceive . "\n";
$size = strlen($line);

if(stristr("$update", "$email"))
echo "update=false";
} else {
fputs($fp, $line, $size);
fclose($fp);
echo "update=true";



echo "alldone=yes";

?>
[Removed the PHPmanual tags, and added the PHP tags for real eyecandy ;) --JAM]


here is what I got so far....this is what I think I am doing wrong...the stristr thing can't read directly from the txt file...I think I need to turn text.txt into some kind of different variable so it is readable by stristr...can anyone tell me how to do that? or a code to do that, and I will look it up? Thanks


Thanks,
Chase

P.S. Does anyone know of a forum for flash integrated with php, I can't find any?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Those that are signing up for your forum, are they managed by a text file. Perhaps I should ask if you keep track of them via a text file?

If that's the case, how is the file delimited? Is each user on his or her own line?

Parsing files isn't really that difficult once you ascertain how the file is formatted and what data is in what position on each line. How so is largely arbitrary as you may decide on a format that you want. An example may be ...

Code: Select all

user_name|password|ip|email|start_date|last_login
... or whatever you want.


After that, you can check the manual at php.net and get a lot of tips from looking at the user contributed comments. You may also want to search google under parsing files in PHP.

A good function to keep in mind here is explode().

Anoter option may be to make an array of the file using file() then just iterating over the array checking to see if the user name allready exists.

One last option may be to just have a seperate file of allready taken user names. As the file would be smaller, it would be far easier and faster to parse.

Cheers,
BDKR
Schwalbach
Forum Newbie
Posts: 2
Joined: Sun Dec 07, 2003 11:20 am

Post by Schwalbach »

Hey,

I don't understand what you mean BDKR. All I need is their e-mail, it's for a mailing system, no login's or anything like that. Sorry for the confusion
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Schwalbach wrote:Hey,

I don't understand what you mean BDKR. All I need is their e-mail, it's for a mailing system, no login's or anything like that. Sorry for the confusion
Don't worry about it. I probably read too much into it. :twisted:

Otherwise, did you get it figured out?

Cheers,
BDKR
Post Reply