PHP Help!

Status
Not open for further replies.

nlester

New Member
Messages
10
Reaction score
0
Points
0
Hi,

I am trying to count the number of people who have signed up to my website. When someone signs up, their email address is added to a comma-delimited text file. I want my program to read that file and count the number of email addresses. I thought I would do this by reading the file character-by-character, and counting the @'s. Here's what I wrote:

$myfile = "email_list.txt";
$fh = fopen($myfile, 'r');
$email_num = 0;

while ($char=fgetc($fh)) {
if ($char == "@") {
$email_num = $email_num + 1;
}
}
fclose($fh);


This worked.....at first, but it stopped counting at 14 email addresses. Now, there are currently 20 emails in the file, but the function returns the number 14 every time. Do you have any idea why this happening, and what I can do to fix it? Any help would be MUCH appreciated. Thank you!
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
Hi,

I am trying to count the number of people who have signed up to my website. When someone signs up, their email address is added to a comma-delimited text file. I want my program to read that file and count the number of email addresses. I thought I would do this by reading the file character-by-character, and counting the @'s. Here's what I wrote:

$myfile = "email_list.txt";
$fh = fopen($myfile, 'r');
$email_num = 0;

while ($char=fgetc($fh)) {
if ($char == "@") {
$email_num = $email_num + 1;
}
}
fclose($fh);


This worked.....at first, but it stopped counting at 14 email addresses. Now, there are currently 20 emails in the file, but the function returns the number 14 every time. Do you have any idea why this happening, and what I can do to fix it? Any help would be MUCH appreciated. Thank you!

Your code is absolute right. No problem in your code.
How to store in text file email Address.

You can store one email in one lin or sepreated by , comma then try it
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
Your code is absolute right. No problem in your code.
How to store in text file email Address.

You can store one email in one lin or sepreated by , comma then try it

The order that you store the email adresses in shouldn't make any difference because you are searching for '@' signs, It should work even if you have them all together in one link or all one separate lines.

Are you still having problems?
 
Last edited:

nlester

New Member
Messages
10
Reaction score
0
Points
0
I ended up changing it to file that writes one email address per line, and I counted the number of lines. And now it's counting correctly. I still don't know why it wouldn't keep counting before.... Thanks for your help!
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
Its really odd that it didn't work for you, because I got it to work. Anyway, I'll close this thread, if you have any more questions then please start another thread.

* Closed *
 
Status
Not open for further replies.
Top