My friend wrote two programs for me on my site, #1 picks a random email address from a .txt file and diplays it. Each email address is on a new line. the php for this program is:
<?php
// load the file that contain the ads
$adfile = "/users/ads.txt";
$ads = array();
// one line per ad
$fh = fopen($adfile, "r");
while(!feof($fh)) {
$line = fgets($fh, 10240);
$line = trim($line);
if($line != "") {
$ads[] = $line;
}
}
// randomly pick an ad
$num = count($ads);
$idx = rand(0, $num-1);
echo $ads[$idx];
?>
Program #2 is the one i am having the problem with. It was originally written for me to read a text file and distiguish between email addresses by a comma "," and it worked perfectly this way. but, I want this php program to read from the same text file as #1 (each email address is on a different line) but when i change the "," to "\n" it does not work anymore. The code is copied below, any help would be appreciated. thanks!
<?
function test_data($data, $str) {
for ($i=0;$i<count($data);$i++)
{
if ($data[$i] == $str)
return true;
}
return false;
}
$handle = fopen('email.txt','r');
$data = fread($handle,999);
fclose($handle);
$data = explode("\n",$data);
if (test_data($data,$user))
echo "Account exists.";
else
echo "No account found.";
?>