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!
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!